下列给定程序中,函数fun()的功能是:在字符串的最前端加入n个*号,形成新串,并且覆盖原串。
注意:字符串的长度最长允许79。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序;
include <stdio.h>
include <strzng.h>
include <conio.h>
/*****************found***************/
void fun(char s[], int n)
{
char a[80],*p;
int i;
/*****************found***************/
s=p;
for(i=0; i<n; i++) a[i]='*';
do
{a[i]=*p;
/*****************found***************/
i++;
}while(*p);
a[i]=0;
strcpy(s,a);
}
main()
{ int n;char s[80];
clrscr();
printf("\nEnter a string:");gets(s);
printf("\nThe string\%s\n",s);
printf("\nEnter n(number of*):");scanf ("%d",&n);
fun(s,n);
printf("\nThe string after inster: \%s\n",s);
}
第1题
组b中并输出,把其他字符保存在N[10]中。
例如:当str1=“ab123456789cde090”时,结果为:
0: 2 1: 1 2: 1 3: 1 4: 1 5: 1 6: 1 7: 1 8: 1 9:2 other charactor:5
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include <conio.h>
main()
{
int i,b[11];
char *str="abl23456789cde090";
char *p=str;
clrscr();
printf("***the origial data ***\n");
puts(str);
for(i=0;i<11;i++)
b[i]=0;
while(*p)
{
switch(【 】)
{
case '0':b[0]++;break;
case '1':b[1]++;break;
case '2':b[2]++;break;
case '3':b[3]++;break;
case '4':b[4]++;break;
case '5':b[5]++;break;
case '6':b[6]++;break;
case '7':b[7]++;break;
case '8':b[8]++;break;
case '9':b[9]++;break;
【 】
}
【 】
}
printf("****** the result ********\n");
for(i=0;i<10;i++)
printf("\n%d:%d",i,b[i]);
printf("\nother charactor:%d",b[i]);
}
第2题
中。
例如,若二维数组中的数据为:
W WWW
S S S S
H H H H
则字符串中的内容应是WSHWSHWSHWSH。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
define M 3
define N 4
void fun(char (*s)[N],char *b)
{
}
main()
{
char a[100],w[M][N]={{ 'W', 'W', 'W', 'W'},
{'S', 'S', 'S', 'S'},{'H', 'H', 'H', 'H'}};
int i,j;
printf("The matrix:\n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
printf("%3c",w[i][j]);
printf("\n");
}
fun(w,a);
printf("The A string:In");
puts(a);
printf("\n\n");
}
第3题
以下程序运行后的输出结果是【 】。
main()
{ int p[7]={11,13,14,15,16,17,18};
int i=0,j=0;
while(i<7&&p[i]%2==1)j+=p[i++];
printf("%d\n",j);
}
第4题
请编写函数fun(),其功能是:计算并输出下列多项式的值。
S=1+4/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如,着主函数从键盘给n输入50后,则输出为 S=1.960784。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf ("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\n\ns=%f\n\n", s);
}
第5题
i所指的变量中,最大公约数放在指针变量yue所指的变量中。
注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
vOid fun(int m,int n,int*bei,int*yue)
{int s=l,i;
if(m>n){s=m;m=n;n=S;}
for(i=2,s=1;i<m i++)
if((m%i=0)&&(n%i=0))
{
}
*yue=s;
*bei=S*m*n;
}
main( )
{int a,b,beishu,yueshu;
chscr( );
printf("please input a,b:");scanf("%d,%d,"&a,&b);
fun(a,b,&beishu,&yueshu);
printf("a,b beishu:%d\n",beishu);
printf("a,b yueshu:%d\n",Yueshu);
}
第6题
请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是将大于整数m且紧靠m的k个非素数存入所指的数组中。
例如,若输入15,5,则应输出16,18,20,21,22。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
void fun(int m,int k,int xx[])
{
}
main()
{
int m,n,zz[1000];
clrscr();
printf("\nPlease enter two integers:");
scanf("%d%d",&m,&n);
fun(m,n,zz);
for(m=0;m<n;m++)
printf("%d",zz[m]);
printf("\n");
}
第7题
下列程序的输出结果是【 】。
main()
{
int a=1,b=2;
a=a+b;b=a-b;a=a-b;
prrintf("%d,%d\n",a,b) ;
}
第8题
请编写函数fun(),它的功能是计算下列级数和,和值由函数值返回。
S=1+x+x2/2!3/3!+…/xn/n!
例如,当n=10,x=0.3时,函数值为1349859。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
include<math.h>
double fun(double x, int n)
{
}
main ()
{
clrscr ();
printf ("%f ",fun(0,3,10));
}
第9题
请补充main 函数,该函数的功能是:计算两个自然数n和m(m<10000)之间所有数的和(n和m从键盘输入)。
例如:当n=1,m=100时,sum=5050:当n=100,m=1000时,sum=495550。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
main ()
{
int n, m;
long sum;
【 】
clrscr ();
printf ("\nInput n,m\n");
scanf ("%d, %d", &n, &m);
while (n<=m)
{
【 】
n++;
}
printf ("sum=%【 】\n", sum);
}
第10题
序连接到t串的后面。例如:当s中的字符串为ABCDE时,则t中的字符串应为EDCBAABCDE。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
void fun (char *s, char *t )
{
int i,sl;
sl=strlen(s);
for (i=0;i<sl;i++)
t[i]=s[sl-1];
for (i=0; i<sl; i++)
/*************found**************
t [sl+i]=s [i];
t [2*sl]-'\0';
}
main ( )
{ char s[100], t[100];
clrscr();
printf("\nPlease enter string s: ");
scanf ("%s", s);
fun (s,t);
printf ("The result is: %s\n",t);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!