填空题请补充函数fun,该函数的功能是比较字符串str1和str2的大小,井返回比较的结果。 例如: 当str1=“cdef",str2=“cde”时,函数fun()返回“>”。 注意:部分源程序给出如下。 请勿改动主函数main 和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: # include< stdio, h> #include<conio. h> #define N 80 char *fun (char *str1,char *str2) char *p1=str1, *p2=str2; while (*p1 if( 【2】 ) return ">"; p1++; p2++; if (*p1=*p2) return "=="; if (*p1== 【3】 ) return "<"; else return ">"; main() char str1 [N], str2 [N]; clrscr (); printf ("Input str1: /n"); gets (str1); printf ("Input str2: /n"); gets (str2); printf ("/n*****the result*****/n"); printf ("/nstr1 %s str2", fun (str1, str2) );
填空题下列程序的运行结果是:【 】
#include <string.h>
char *ss(char *s)
{ return s+strlen(s)/2;}
main( )
{ char *p,*str=”abcdefgh”;
p=ss(str); printf(“%s\n”,p);}
填空题在Windows环境下,只要在“开始”菜单中单击【 】选项,就可以查阅最近打开过的文档清单。
填空题在循环中,continue语句与break语句的区别是:______语句只是结束本次循环,然后进行循环的条件判定。
填空题有以下程序: void f(int*x,iht * y) int t; t=*x;*x;=*y;*y=t; main() int a[8]=1,2,3,4,5,6,7,8,i,*p,*q; p=a;q= while(p) f(p,q);p++;q--; for(i=0;i<8;i++)printf("%d,",a[i]); 程序运行后的输出结果是{{U}} {{/U}}。
填空题下列程序能将字符串s1中的所有与字符串str1相同的子串替换成字符串sb2,并将替换后的新串存于字符数组s2中。 #include<stdio. h> void replace(s1,s2,str1,str2) char *s1,*s2,*str1,*str2; char *t0,*t1,*t2,*x,*y; x=s1;y=s2; while( 【8】 ) for(t0=s1,t1=str1; ((*t1!='/O't0++,t1++); if(*t1!='/0') *s2++= 【10】 ; else for(t1=str2;*t1!='/0';) *s2++= 【11】 ; 【12】 ; *s2='/0'; main () static char s1[]="abcdef ababcd abab.",s2125]; replace (s1, s2, "abc", "XYZ"); printf("%s/n",s2);
填空题用以下语句调用库函数malloc,使字符指针st指向具有11个字节的动态存储空间,请填空。 st=(char*) 【19】 ;
填空题函数fun()的功能是:统计长整数n的各位上出现的数字1、2、3的次数,并用外部(全局)变量c1、c2、c3返回主函数。
例如,当n=123114350时,结果应该为:c1=3 c2=1 c3=2。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的标号处填入所编写的若干表达式或语句。
试题程序 #include
<stdio.h> int c1, c2, c3; void fun (long
n) { c1=c2=c3=0 while(n) {
switch (______) { case 1:c1++; ______; case 2:
c2++; ______; case 3: c3++; }
n/=10; } } main()
{ long n=123114350L; fun (n);
printf("/nThe result:/n"); printf("n=% id c1=% d c2 =% d c3 =%
d/n", n, c1, c2, c3); }
填空题设二进制数A是00101101,若想通过异或运算A^B使A的高4位取反,低4位不变,则二进制数B应是 【12】 。
填空题以下程序是从终端读入数据到数组中,统计其中正数的个数,并计算它们的和。请填空。
main()
{
int i,a[20],sum,count;
sum=count={{U}} 【17】 {{/U}};
for(i=0;i<20;i++)scanf("%d",{{U}} 【18】 {{/U}});
for(i=0;i<20;i++)
{
if(a[i]>0)
{ count++:
sum+={{U}} 【19】 {{/U}};
}
}
printf("sum=%d,count=%d/n",sum.count);
}
填空题下列给定程序中,函数fun的功能是:求整数x的y次方的低3位值。例如,整数5的6次方为15625,此值的低3位值为625。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
long fun(int x,int y,long*p)
{
int i;
long t=1;
/**********found**********/
for(i=1;i<y;i++)
t=t*x;
*p=t;
/**********found**********/
t=t/1000;
return t;
}
void main()
{
long t,r;int x,y;
printf("/nInput x and y:");
scanf("%ld%ld",
t=fun(x,y,
printf("/n/nx=%d.y=%d,r=%ld,last=%ld/n/n",x,y,r,t);
}
填空题以下程序用于判断a、b、c能否构成三角形,若能,输出YES,否则输出NO。当给a、b、c输入三角形三条边长时,确定a、b、c能构成三角形的条件是需同时满足三个条件:a+b>c,a+c>b,b+c>a。
请填空。
main()
{ float a,b,c;
scanf("%f%f%f",
if({{U}} 【7】 {{/U}}) printf("YES/n"); /*a、b、c能构成三角形*/
else printf("NO/n"); /*a、b、c不能构成三角形*/
}
填空题诊断和改正程序中错误的工作通常称为 【1】 。
填空题已知文本文件test.txt,其中的内容为:Hello,everyone!。以下程序中,文件test.txt已正确为“读”而打开,由此文件指针fr指向文件,则程序的输出结果是______。 #include <stdio.h> main() FILE *fr; char str[40]; fgets(str, 5 ,fr); printf("%s/n",str); fclose(fr);
填空题以下程序运行后的输出结果是{{U}} 【10】 {{/U}}。
main()
{int a[4][4]={{1,2,3,4},{5,6,7,8},{11,12,13,14},{15,16,17,18}};
int i=0,j=0,s=0;
while(i++<4)
{
if(i==2||i==4)continue;
j=0;
do{ s+=a[i][j]; j++;}while(j<4);
}
Printf("%d/n",s);
}
填空题请补充fun函数,该函数的功能是:按'0'到'9'统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。 例如,输入“x=1123.456+0.909*bc”,结果为:1=2,3=1,5=1,7=0,9=2。 [注意] 部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。 [试题源程序] #include<conio.h> #include<stdio.h> #define N 20 fun(char*tt, int num[]) int i, j; int bb[10]; char *p=tt; for(i=0;i<10; i++) num[i]=0; bb[i]=0; while( (1) ) if(*p>='0'&&*p<='9') (2) ; p++; for(i=i, J=0; i<10; i=i+2, j++) (3) ; main() char str[N]; int num[10], k; cirscr(); printf("/nplease enter a string:"); gets(str); printf("/n*******The original string*******/n"); puts(str); fun(str, num); printf("/n******The number of letter********/n”); for(k=0; k<5; k++) printf("/n"); printf("%d=%d ", 2*k+1, hum[k]); printf("/n"); return;
填空题下列给定的程序中,函数fun的功能是:计算并输出k以内最大的10个能被13或17整除的自然数之和。k的值由主函数传入,若k的值为500,则函数的值为4622。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int fun(int k)
{int m=0,mc=0,j;
while((k>=2)mc++;}
k--;
/*********found*********/
return m;
}
void main()
{system("CLS");
printf("% d/n",fun(500));
}
填空题以下程序的输出结果是{{U}} 【10】 {{/U}}。
#include<string.h>
main()
{ printf("%d/n",strlen("IBM/n012/1//"));}
填空题有一个已排好序的数组,今输入一个数,要求按原来的顺序规律将它插入到数组中。算法是:假设排序顺序是从小到大,对输入的数,检查它在数组中哪个数之后,然后将比这个数大的数顺序后移一个位置,在空出的位置上将该数插入。请在程序中的空白处填上一条语句或一个表达式。 #define N 100 main() float a[N+1],x; int i,p; for(i=0;i<N;i++) scanf("%f" scanf("%f", for(i=0,p=N;i<N;i++) if(x<a[i]) ______; break; for(i=N-1;______;i-) a[i+1]=a[i]; a[p]=x; for(i=0;______;i++) printf("%8.2f",a[i]); if(i%5=0) printf("/n");
填空题下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(即下标值),若未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。
请在程序的下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#include<string.h>
#define N 5
#define M 8
int fun(char(*ss)[M],char*t)
{int i;
/**********found**********/
for(i=0;i<______;i++)
/**********found**********/
if(strcmp(ss[i],t)==0)return______;
return-1;
}
main()
{char ch[N][M]={"if","while","switch","int","for"},t[M];
int n,i;
printf("/nThe original string/n/n");
for(i=0;i<N;i++)puts(ch[i]);
printf("/n");
printf("/nEnter a string for search:");gets(t);
n=fun(ch,t);
/**********found**********/
if(n==______)printf("/nDon"t found!/n");
else printf("/nThe position is%d./n",n);
}
