以下程序用以删除字符串中所有的空格,请填空。
include<stdio.h>
main()
{char s[100]={"Our teacher teach C language!"};int i,j;
for(i=j=0;s[i]!='\0';i++)
if(s[i]!=''){()}
s[j]='\0';
printf("%s\n",s);
}
第1题
性表的顺序存储中,元素之间的逻辑关系是通过【 】决定的;性表的链接存储中,元素之间的逻辑关系是通过【 】决定的。
第2题
请编写函数fun(),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
float fun (float *a, int n)
{
}
main ()
{
float score[30]=(90.5,72,80,61.5,55},
aver;
aver=fun(score, 5);
printf("\nAverage score is: %5.2f
\n",aver);
}
第4题
串中字母之间的*号都不删除。形参n给出了字符串的K度,形参h给出了字符串中前导*号的个数,形参e给出了字符山中最后*号的个数。在编写函数时,不得使用c语言提供的字符串函数。
例如,若字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的内容则应当是A*BC*DEF*G。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <conio.h>
void fun (char *a;int n ,int h ,int e)
{
}
main ( )
{
char s [81],*t,*f;
int m=0,tn=0, fn=0;
printf("Enter a string :\n");
gets (s);
t=f=s;
while (*t)
{t++;m++; } /*m为字符串的长度*/
t--; /*指针t指身字符串尾部*/
while (*t=='*')
{t--; tn++; }
/*指针t指向最后一个字母,tn统计尾部'*'的个数*/
while (*f=='*' )
{f++;fn++;}
/*指针f指向第一个字母,tn统计导'*'的个数*/
fun( s, m, fn, tn);
printf ("The string after deleted: \n");
puts (s);
}
第5题
请补充函数fun(),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
int fun (char s[],char ch)
{
int i=0, n=0;
while(【 】)
{
if(【 】)
n++;
i++;
}
【 】;
}
main ( )
{
int n;
char str[N], ch;
clrscr ();
printf ("\nInput a string: \n");
gets (str);
printf ("\nInput a charactor: \n" ;
scanf ("%c", &ch);
n=fun (str, ch);
printf("\nnumber of %c:%d", ch, n);
}
第6题
的所有字符都删除,串中剩余字符所形成的一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为ABCDEFG12345,其中字符B的ASCII码值为偶数,所在元素的下标为奇数,因此必须删除;而字符A的ASCII码值为奇数,所在数组中的下标为偶数,因此不应当删除,其他依次类推。最后t所指的数组中的内容应是ACEG。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
include<string.h)
void fun(char *s, char t[])
{
}
main()
{
char s[100],t[100];
clrscr();
printf("\nPlease enter string s:");
scanf("%s",s);
fun(s,t);
printf("\nThe result is: %s\n",t);
}
第7题
迭代)。
π/2=1+1/3+1*2/(3*5)+1*2*3/(3*5*7)+1*2*3*4/(3*5*7*9)+…
+1*2*3*…*n/(3*5*7*…*(2n+1))
程序运行后,如果输入精度0.0005,则程序输出3.14…。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<math.h>
double fun(double eps)
{
}
main()
{
double x;
printf("Input eps: ");
scanf("%1f", &x);
printf("\neps=%1f,PI=%1f\n",x,fun(x));
}
第8题
请补充函数fun,其功能是:计算并输出给定10个数的方差:
例如,给定的10个数为15.0,19.0,16.0,15.0,18.0,12.0, 15.0,11.0,10.0,16.0,输出为s=2.758623。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<math. h>
double fun (double x[10])
{
int i;
double avg=0.0;
double sum=0.0;
double abs=0.0;
double sd;
for (i=0; i<10; i++)
【 】;
avg=sum/10;
for(i=0;i<10;i++)
【 】;
sd=【 】;
return sd;
}
main()
{
double s,x[10]={15.0,19.0,16.0,15.0,
18.0,12.0,15.0,11.0,10.0,16.0};
int i;
printf("\nThe original data is :\n");
for(i=0;i<10;i++)
printf("%6.1f",x[i]);
printf("\n\n");
s=fun(x);
printf("s=%f\n\n",s);
}
第9题
然有序。
例如,在数组bb[N]={12,23,31,44,51,63,71,79,85,95}中插入93,结果为:
bb[N]{11,21,31,41,51,61,7l,79,8l,93,95}
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<std/o. h>
define N 10
main()
{
int i,j;
int n;
int bb IN+l] ={ t2,23, 31, 44, 51, 63, 71,
79,85,95};
clrscr ();
printf("\nInput n \n");
scanf ("%d", &n);
printf ("\nn=%d ",n);
printf("\n*** original list ***In");
for (i=0; i<N; i++)
printf ("%4d ",bb [ii );
for (i=0; i<N; i++)
{
if (n<=bb [i ] )
{
for(j=N;【 】;j--)
【 】;
bb [j] =n;
【 】;
}
if (i=N)
bb[i]=n;
printf("\n***** new list ******In");
for (i=0;i<N+l; i++)
printf ("%4d ",bb [i]);
}
第10题
主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。例如,当字符串中的内容为abcdabfabcdx,t中的内容为ab时,输出结果应是abcdx。当字符串中的内容为abcdabfabcdx,t中的内容为abd时,则程序输出未找到的信息:Not found!
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
include <conio.h>
include <string.h>
char *fun(char *s,char *t)
{
char *p,*r,*a;
/*************found**************/
a=Null;
while(*s)
{ p=s;r=t;
while(*r)
/*************found**************/
if(r= =p) {r++;p++;}
else break;
if(*r=='\0') a=s;
s++;
}
return a;
}
main()
{char s[100],t[100],,*p;
clrscr();
printf("\nPlease enter string S: ");
scanf("%s",s);
printf("\nPlease enter substring t: ");
scanf("%s",t);
p=fun(S,t);
if(p) printf("\nThe result is:%s\n",p);
else printf("\nNot found!\n ");
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!