简答题 | 以下程序运行后的输出结果是 【14】 main() { int i,j,a[][3]={1,2,3,4,5,6,7,8,9}; for(i=0;i<3;i++) for(j=i+1;j<3;j++) a[j][i]=0; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d ",a[i][j]); printf("\n"); } } |
查看答案 |
简答题 | 输入一行字符以’\n’作为输入结束符,分别统计出其中英文字母,空格,数字和其他字符的个数。 | 查看答案 |
简答题 | 求一个3*3矩阵对角线元素之和。 | 查看答案 |
简答题 | 编程计算圆面积和圆周长。设圆半径r=1.5,面积为s。要求用scanf函数输入半径,输出结果中应包含适当的文字说明。 | 查看答案 |
简答题 | 有一个4╳5的矩阵,要求编程求出其中值最小的那个元素的值,以及其所在的行号和列号。 | 查看答案 |
简答题 | 题目:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。 程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。 |
查看答案 |
简答题 | 题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。 | 查看答案 |
简答题 | 试编程判断输入的正整数是否既是5又是7的整倍数。若是,则输出yes;否则输出no。 | 查看答案 |
简答题 | 若有数组:int a[2][3] ={{1,2,3},{4,5,6}}; 现要将a的行和列的元素互换后存到另一个二维数组b中,并以矩阵形式输出数组b。试编程。 | 查看答案 |
简答题 | 编程计算下列表达式:s=1!+2!+3!+4!+……+10! | 查看答案 |
简答题 | 从键盘上输入a与n的值,计算sum=a+aa+aaa+aaaa+……(共n项)的和。例a=2, n=4, 则sum=2+22+222+2222。 | 查看答案 |
简答题 | 求1-100之间的奇数和及偶数的和。 | 查看答案 |
简答题 | 求元素个数为10的一维数组元素中的最大值和最小值。 | 查看答案 |
简答题 | 请补充函数proc(),其功能是:计算并输出给定10个数的方差。 例如,给定的l0个数为12.0,9.0,26.0,5.0,6.0,31.0,9.0,3.0,8.0,18.0,输出为S=8.877500。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proe()的横线上填人所编写 的若干表达式或语句。 试题程序: #include #include double proc(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++) 【1】 ; avg=sum/10; for(i=0;i<10;i++) 【2】 ; sd= 【3】 ; return sd; }void main(){ double s,str[10]={12.0,9.0,26.0,5.0,6.0,31.0,9.0,3.0,8.0,18.0}; int i; printf("\nThe original data is:\n"); for(i=0;i<10;i++) printf("%6.If",str[i]); printf("\n\n"); s—proc(str); printf("s=%f\n\n",s); } |
查看答案 |
简答题 | 下列给定程序中函数proc的功能是:取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。例如,当s中的数为l23456789时,t中的数为2468。请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #include //****found**** void proc(long S,long t){ long sl=10; s/=10; *t=s%10; //****found**** while(s<O) { s=s/l00; *t=s%10*sl+*t; s1=sl*10;} } void main() {long S,t; system("CLS"): printf("\nPlease enter S:"); scanf("%ld",&s); proc(S,&t); . printf("The result is:%ld\n",t); } |
查看答案 |
简答题 | 编写一个函数,从传人的M个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标志)。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include #include #include char*proc(char(*a)[81],int num) { } void main() { char ss[l0][81],*max; int n,i=0; printf("输入若干个字符串:"); gets(ss[i]); puts(ss[i]); while(!strcmp(ss[i],"****")= =0) { i++: gets(ssEi]); puts(ss[i]); } n=i: max=proe(SS,n); printf("\nmax=%s\n",max); } |
查看答案 |
简答题 | 请补充main()函数,亥函数的功能是求方程ax2+bx+ e=0的两个实数根。方程的系数a、b、C从键盘输入,如果判别式(disc=b*b-4*a*c)小于0,则要求重新输入a、b、c的值。 例如,当a=1,b=2,c=1时,方程的两个根分别是:x1 =-1.00,x2=-1.00。 注意:部分源程序给出如下。 请勿改动函数中的其他任何内容,仅在横线上填入所编写的若干表达式或语旬。 试题程序: #include #include void main() { double a,b,c,x1,x2,disc; do { printf("Input a,b,C:"); scanf("%1f,%1f,%1f”,&a,&b,&C); disc=b*b一4*a*C: if(disc<0) printf("disc=%1f\n Input again!\n",disc); } while(【1】); printf("****1he result****\n"); x1=(-b+【2】 (disc))/(2*a); x2=(-b-【3】(disc))/(2*a); printf("\nx1=%6.21f\nx2=%6.21f\n",x1,x2); } |
查看答案 |
简答题 | 已知一个数列从0项开始的前3项为0,0,1,以后的各项都是其相邻的前3项之和。下列给定的程序中,函数proc ()的功能是:计算并输出该数列前n项的和sum。n的值通过形参传人。例如,当n=20时,程序的输出结果应为42762.000000。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动maiil()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #include double proc(int n) { double sum,s0,s1,s2,s; int k; sum=1.0; if(n<=2) sum=0.0; s0=0.0; s1=0.0; s2=1.0; //****found**** for(k=4;k<N;K++) } { s=s0+s1+s2; sum+=S: s0=s1; s1=s2; //****found**** s2=s; return sum; } void main() { int n; system("CLS"); printf("Input N="); scanf("%d",&n J; printf("%f\n",proc(n)); } |
查看答案 |
简答题 | 请编一个函数void proc(int ttEM][N],int pp[N]),tt 指向一个M行N列的二维数组,求出二维数组每行中最大元素,并依次放入pp所指的一维数组中。二维数组中的数已在主函数中给出。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。 试题程序: #include #include #include #define M 3 #define N 4 void proc(int ttrM3rN]。int pp[N]) { } void main() { int str[M][N]={ {34,56,84,78}, {23,84,93,12), {28,38,39,93}}; int p[N],i,j,k; system("CLS"); printf("The riginal data is:\n"); for(i=0;i<M;I++) { for(j=0;j<N;J++) printf("%6d",str[i][j]); printf("\n"); } proc(str,p); printf("\nThe result is:\n");for(k=0:k<M;K++) printf("%4d",p[k]); printf("n");} |
查看答案 |
简答题 | 请补充函数proc(),该函数的功能是按条件删除一个字符串指定字符一半的数目,具体要求如下:如果该字符串所包含的指定字符的个数是奇数,则不删除,如果其数目是偶数,则删除原串后半部分的指定字符。其中,str指向原字符串,删除后的字符串存放在b所指的数组中,c中存放指定的字符。例如,当str输入“abcabcabcab”,c=b时,b的输出为“abcabcaca”;如果str的输入为“abcabcabca”,则b的输出为“abcabcabca”。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅程函数prOC()的横线上填入所编写的若干表达式或语句。 试题程序: #include #include #include #define M 80 void proc(char str[],char b[],char c) { int i=0,j=0; int n=0: int m=0: while(str[i]!='\0') { if(str[i]==c) n++: i++: } 【1】 ; if(n%2) { while(str[j]!='\0 ') { b[j]=str[j]; j++; } b[j]='\0'; } else { while(str[i]!='\0 ') { b[j++]=str[i]; if(str[i]==c) m++: if((m>n/2)&&(str[i]==c)) 【2】 ; i++: } 【3】 ; } } void main() { char str[M],b[M]; char C; system("CLS"); printf("Enter the strin9:\n"); gets(str); printf("Enter the character of the string deleted:"): scanf("%C",&c); proc(str,b,c); printf("The new string is:%s\n",b); } |
查看答案 |
简答题 | 下列给定程序中,函数proc()的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码升序排序后输出。 例如,输入opdye,则应输出deopy。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #include #include //****found**** int proc(char str[]) { char c; unsigned i,j; for(i=0;i<STRLEN(STR)-1;I++) for(j=i+1;j<STRLEN(STR);J++) if(str[i]>str[j]) { c=str[j]: //****found**** str[j]=str[i++]; str[i]=c; } } void main() { char str[81]; system("CLS"); printf("\nPlease enter a character string:"); gets(str); printf("\n\nBefore sorting:\n%s",str); proc(str); printf("\nAfter sorting decendingly:\n %s",str); } |
查看答案 |
简答题 | 请编写一个函数proc(),它的功能是:求出1~m(含m) 能被7或11整除的所有整数放在数组a中,通过n返回这些数的个数。 例如,若传给m的值为70,则程序输出: 7 11 14 21 22 28 33 35 42 44 49 55 56 63 66 70 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include #include #include #define N 100 void proc(int m,int*a,int*n) { } void main() { int arr[N],n,k; system("CLS"); proc(70,arr,&n); for(k=0;k<N;K++) if((k+1)%20==0)//每行输出20个数 { printf("%4d",arr[k]); printf("\n"); } else printf("%4d",arr[k]); printf("\n"); } |
查看答案 |
简答题 | 请补充函数proc(),函数proc()的功能是求7的阶乘。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。 试题程序: #inelude<STDIO.h> long proc(int n) { if(【1】) return(n*proc(【2】); else if(【3】) return 1; } void main() { int k=7; printf("%d!=%1d\n",k,proc(k)); } |
查看答案 |
简答题 | 下列给定程序中,函数proc()的功能是计算正整数m 各位上数字的平方和。 例如,输入498,则输出应该是161。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<STDLIB.h> #include<STDIO.h> #include<CONIO.h> long proc(10ng m) { //****found**** long sum=1; do { sum+=(m%10)*(m%10); m/=l0; //****found**** } while(m) return(sum); } void main() { long n; system("CLS"); printf("Please enter a number:"); scanf("%1d",&n); printf("\n%ld\n",proc(n)); } |
查看答案 |
简答题 | 假定输入的字符串中只包含字母和*号。请编写函数proc(),它的功能是:将字符串中的前导*号全部删除,中间和后面的*号不删除。 例如,若字符串中的内容为****a*bc*def*g** **,删除后,字符串中的内容则应当是a*bc*def*g** **。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。 试题程序: #include<STDIO.h=:{> #include<CONIO.h> woid proc(char*st r) { } void main() char str[81]; printf("Enter a string:\n"); gets(str); proc(str): printf("The string after deleted:\n"); puts(str);} |
查看答案 |
简答题 | 请补充main()函数,该函数的功能是:把一个整数插入一个已经按从小到大排序的数组中。插入后,数组仍然有序。 例如,在数组bb[M]={10 20 30 40 50 60 70 80 85 95} 中插入75,结果为 bb[M]={10 20 30 40 50 60 70 75 80 85 95} 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #include #include #define M 10 void main() { int i,j; int n; int bb[M+1]={10,20,30,40,50,60,70,80,85,95}; system("CLS"); printf("\nlnput n n"); scanf("%d",&n); printf("\nn=%d",n); printf("\n***original list***\n"); for(i=0;i<M;I++) printf("%4d",bb[i]); for(i=0;i<M;I++) { if(n<=bb[i]) { for(j==M;【1】 ;j--) 【2】 ; bb[j]=n; 【3】 ; } } if(i==M) bb[i]=n: printf("\n****new list****\n"); for(i=0;i<M+1;I++) printf("%4d",bb[i]); } |
查看答案 |
简答题 | 下列给定程序中,函数proc()的功能是找出100~m(m 不大于1000)之间百位数字加十位数字等于个位数字的所有整数,把这些整数放在s所指的数组中,个数作为函数值返回。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #define M 1000 int proc(int*S.int n) { int i,j,k,a,b,c; j=0; for(i=100;i<N;I++) { //****found**** k=n: a=k%10; k/=10; b=k%10; c=k/10; if(a==b+c) //****found**** s[j]=i: } return j; } void main() { int a[M],m,num=0,i; do { printf("\nEnter m(<=1000):"); scanf("%d",&m); } while(m>1000); num=proc(a,m); printf("\n\nThe result:\n"); for(i=0;i<NUM;I++) printf("%5d",a[i]); printf("\n\n"); } |
查看答案 |
简答题 | 请编写函数proc(),其功能是:计算并输出下列多项式值。 S=(1-1/2)+(1/3-1/4)+…+(1/(2n-1)-1/2n) 例如,若主函数从键盘给n输入20后,则输出为S= 0.680803。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。 试题程序: #include t:stdio.h> double proc(int n) { } void main() { int n; double slim; printf("\nInput n:"); scanf("%d",&n); sum=proc(n)。 printf("\ns=%f\n",sum); } |
查看答案 |
简答题 | str是一个由数字和‘,:母字符组成的字符串,由变量num传人字符串长度。请补充函数proc(),该函数的功能是:把字符串str中的数字字符转换成数字并存放到整型数组bb中,函数返回数组bb的长度。 例如,str="abc3de987f9621",结果为:3987621。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。 试题程序: #include #define M 80 int bb[M]; int proc(char str[],int bb[],int num) { int i,n=0; for(i=0;i<NUM;I++) { if(【1】) { bb[n]=【2】: n++: } } return 【3】 ; } void main() { char str[M]; int mum=0,n,i; printf("Enter a strin9:\n"); gets(str); while(str[num]) num++: n=proc(str,bb,num); printf("\nbb="); for(i=0;i<N;I++) printf("%d",bb[i]); } |
查看答案 |
简答题 | 下列给定的程序中,函数proc()的功能是:判断字符ch 是,与str所指字符串中的某个字符相同;若相同,则什么也不做,若不同,则将其插在串的最后。请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #include #include //****found**** void proc(char str,char ch) { while(*str &&*str!=ch)str++; //****found**** if(*str==ch) { str[0]=ch; //****found**** str[1]='0': } } void main() { char str[81],ch; system("CLS"); printf("\nPlease enter a string:"); gets(str); printf("\n Please enter the character to search:"); ch=getchar(); proc(str,ch); printf("\nThe result is%s\n",str); } |
查看答案 |
简答题 | 学生的记录由学号和成绩组成,M名学生的数据已在主函数中放人结构体数组stu中,请编写函数proc(),它的功能是:把指定分数范围之外的学生数据放在b所指的数组中,分数范围之外的学生人数由函数值返回。 例如,输入的分数是70和79,则应当把分数低于70和高于79的学生数据输出,不包含70分和79分的学生数据。主函数中把70放在low中,把79放在heigh中。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include #define M 16 typedef struct { char num[10]; int s: } STREC; int proc(STREC*a,STREC*b,int 1,int h) { } void main() { STREC stu[M]={{"GA005",55),{"GA003",96}, {"GA002",80),{"GA004",68), {"GA001",88},{"GA007",74}, {"GA008",85),{"GA006",89}, {"GA015",90),{"GA013”,53), {"GA012",66},{"GA014”,82), {"GA011",73},{"GA017",69), {"GA018",64),{"GA016",86}}; STREC h[M]; int i,n,low,heigh,t; printf("Enter 2 integer number low& heigh:"); scanf("%d%d",&low,&heigh); if(heigh { t=heigh: heigh=low; low=t; } n=proc(stu,h,low,heigh); printf("The student’S data out %d--%d:\n",low,heigh); for(i=0;i<N;I++) printf("%S%4d\n",h[i].num,h[i].s); //输出指定分数范围内的学生记录 printf("\n"); } |
查看答案 |
简答题 | 请补充main()函数,该函数的功能是:从键盘输入一个字符串及一个指定字符,然后把这个字符及其后面的所有字符全部删除。结果仍然保存在原串中。 例如,输入“abcdefg”,指定字符为“d”,则输出“abe”。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填入所编写的若干表达式或语句。 试题程序: #include #include #define M 80 void main() { int i=0; char str[M]; char ch; system("CLS"); printf("\n Input a strin9:\n"); gets(str); printf("\n Input a charator;\n"); scanf("%c",&ch); while(str[i]!='\0') { if(str[i]==ch) 【1】 【2】 ; } str[i]=【3】 ; printf("\n***display string***\n"); puts(str); } |
查看答案 |
简答题 | 下列给定程序的功能是:读入一个整数n(2<=n<= 5000),打印它的所有为素数的因子。例如,若输入整数1234,则应输出:2,617。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main()函数,不能增选或删行,也不能匿改程序的结构。 试题程序: #include #include //****found**** Prime(int m); { int j,P; p=1; //****found**** for(j=2;j<M;J++) if!(m%j) { p=0; break; } return(p); int i,n; printf("\nplease enter an integer number between2 and 5000:"); scanf("%d",&n); printf("\n\nThe prime factor(s)of%d is(are):",n): for(i=2;i<N;I4+) if((!(n%i))&&(Prime(i))) printf("%4d,",i); printf("\n"); } |
查看答案 |
简答题 | 请编写函数proc(),该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。 例如,若字符串数组中的M个字符串为: ABCD BCDEFG CDEFGHI 则合并后的字符串内容应该是ABCDBCDEFGCDEF—GHl。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include #include #define M 3 #define N 20 void proc(char arr[M][N],char*b) { } void main() { char str[M][N]={"ABCD","BCDEFG"," CDEFGHI"},i; char arr[100]={"############# #####"); printf("The string:\n"); for(i=0;i<M;I++) puts(str[i]); printf("\n"); proc(str,arr); printf("The A string:\n"); printf("%s",arr); printf("\n\n"); } |
查看答案 |
简答题 | 给定程序的功能是将n个人员的考试成绩进行分段统计,考试成绩放在a数组中,各分段的人数存到b数组中:成绩为60~69的人数存到b[0]中,成绩为70~79的人数存到b[1]中,成绩为80~89的人数存到b[2]中,成绩为90~99的人数存到b[3]中,成绩为100的人数存到b[4]中,成绩为60分以下的人数存到b[5]中。 例如,当a数组中的数据是:93、85、77、68、59、43、94、75、98,调用该函数后,b数组中存放的数据应是:1、2、1、3、0、2。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在横线上填入所编写的若于表达式或语句。 试题程序: #includedstdi0.h> void fun(int a[],int b[],int n) { int i; for(i=0;i<6;I++) b[i]=0; for(i=0:i<【1】 ;i++) if(a[i]<60) b[5]++; 【2】 b[(a[i]一60)/10]++; } void main() { int i,a[100]={93,85,77,68,59,43,94,75,98),b[6]; fun(【3】 ,9); printf("the result is:"); for(i=0;i<6;i++) printf("%d",b[i]); printf("\n,"); } |
查看答案 |
简答题 | 下列给定程序中,函数proc()的功能是:根据输入的:个边长(整型值),判断能否构成三角形:若能构成等边三角形,则返回3;若是等腰三角形,则返回2;若能构成三角形则返回l;若不能,则返回0。 例如,输入3个边长为3,4,5,实际输入时,数与数之间以Enter键分隔而不是逗号。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include int proc(int a,int b,int c) { if(a+b>c&&b-c>a&&a+c>b) { if(a==b&&b==c) //****found**** return 1; else if(a==b|| b==C||a==c) return 2; //****found**** else return 3; } else return 0; } void main() { int a,b,c,shape; printf("\nInput a,b,c:"); scanf("%d%d%d",&a,&b,&c); printf("\na=%d.b=%d,c=%d\n",a,b,c); shape=proc(a,b.c): printf("\n\nThe shape:%d\n",shape); } |
查看答案 |
简答题 | 请编一个函数fun(oh lr*str),该函数的功能是把字符串中的内容逆置。 例如,字符串中原有的字符串为asdf9,则调用该函数后,串中的内容为9fdsa。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include #include #include #define N 100 void fun(char * str) { } void main() { char a[N]; FILE*out: printf("Enter a string:"); gets(a); printf("The origir al string is:"); puts(a); fun(a): printf("The string after modified:"); puts(a); strcpy(a,"Welcome!"); fun(a); out=fopen("outfile.dat","w"); fprintf(out,"%s".a); fclose(out); } |
查看答案 |
简答题 | 请补充main()函数,该函数的功能是:计算3名学生各科的平均成绩。 例如,当score[N][M]={{85,62,89.5,60,69),{90,96,84.5,100,85},{92,97,86,73,85))时,五门学科的平均分为:89 85 86.7 77.7 79.7。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填人所编写的若干表达式或语句。 试题程序: #include #include #define N 3 #define M 5 int main() { int i,j; static float score[N][M]一{{85,62,89.5,60,69), {90,96,84.5,100,85},{92,97,86,73,85}}; static float arr[-N]; system("CLS"); for(i=0;i<M;I++) arr[i]=0.0: for(i=0;i<【1】 ;i++) { for(j=0;j<【2】 ;j++) arr[j]+=score[i][j]: } for(i=0;i<M;I++) printf("\nsubject%d\taverage=%5.1f",i+1, 【3】); return 0; } |
查看答案 |
简答题 | 下列给定程序中,函数proc()的功能是:首先把b所指字符串中的字符按逆序存放,然后将str1所指字符串中的字符和Str2所指字符串中的字符,按排列的顺序交叉合并到str所指数组中,过长的剩余字符接在str所指数组的尾部。例如,当str1所指字符串中的内容为ABCDEFG,str2 所指字符串中的内容为1234时,str所指数组中的内容应该为A483C2D1EFG;而当str1所指字符串中的内容为1234,str2所指字符串中的内容为ABCEDFG时,str所指数组中的内容应该为1G2F31:4DCBA。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #include #include void proc(char*strl,char*str2,char*str) { int i,j;char ch; i=0;j=strleu(str2)-1; //****found**** while(i>j) { ch=str2[i];str2[i]=str2[j];str2[j]=ch; i++;j--; } while(*str1||*str2) { if(*str1){*str=*str1;str++;str1++;) if(*str2){*str=*str2;str++;str2++;) } //****found**** *str=0: } void main() { char s1[100],s2[100],t[200]; system("CLS"); printf("\nEnter s1 string:"); scanf("%s",sl); printf("\nEnter s2 string:"); scanf("%s",s2); proc(s1,s2,t); printf("\nThe result is:%s\n",t); } |
查看答案 |
简答题 | 请编写fun()函数,其功能是:计算并输出3~m所有素数的平方根之和。 例如,若主函数从键盘给m输入50后,则输出为s= 68.665791。 请勿改动main()函数与其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。 注意:m的值要大于2但不大于100。部分源程序给出如下。 试题程序: #include #include double fun(int m) { } void main() { int m; double s; FILE*out: printf("\n\nInput m:"); scanf("%d",&m); s=fun(m); printf("\n\ns=%f\n\n",s); out=fopen("outfile.dat","w"); for(m=0;m<10;m++) fprintf(out,"%f\n",fun(m+80)); felose(out); } |
查看答案 |
简答题 | 请补充函数proc(),该函数的功能是:把从主函数中输入的由数字字符组成的字符串转换成一个无符号长整数,并且逆序输出。结果由函数返回。例如,输入:1234567,结果输出:7654321。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填人所编写的若干表达式或语句。 试题程序: #include #include #include stdio.h> #include unsigned long proc(char*str) { unsigned long t=0: int k: int i=0; i=str|en(str); for(【1】 ;i>=0;i--) { k= 【2】 ; t= 【3】 ; } return t; } void main() { char str[8]; system("CLS"); printf("Enter a string made up of'0'to '9 ' digital character:\n"); gets(str); printf("The string,is:%s\n",str); if(strlen(str)>8) printf("The string is too tong!"); else printf("The result:%1u\n", proc(str)); } |
查看答案 |
简答题 | 下列给定程序中,函数p roc()的功能是:先将字符串s 中的字符按顺序存放到t中,然后把S中的字符按正序连接到t的后面。例如,当s中的字符串为WXYZ时,则t中的字符串应为WXYZWXYZ。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #include #include void proc(char*s,char*t) { int i,s1; s1=strlen(s); for(i=0;i<S1;I++) //****found**** t[i]=s[s1]; for(i=0;i<S1;I++) t[s1+i]一s[i]; t[2*s1]='\O0; } void main() { char s[100],t[100]; system("CLS"); print{("\nPlease enter string s:"); scanf("%s",s); proc(s,t); printf("The result is:%s\n",t); } |
查看答案 |
简答题 | 请编写函数proc(),该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。 例如,若二维数组中的数据为 13 23 33 43 14 24 34 44 15 25 35 45 则一维数组中的内容应该是13 23 33 43 14 24 34 44 15 25 35 45。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。 试题程序: #include void proc(int(*s)[103,int*b,int*n,int rain.int nn) { } void main() { int arr[10][10]={{33,33,33,33),{44,44,44,44}, {55,55,55,55}),i,j; int a[l00]={o),n=o; printf("The matrix:\n"); for(i=0;i<3;i++) { for(j=0;j<4;j++) printf("%3d",arr[i][j]): printf("\n"); } proc(arr,a,&n,3,4): printf("The A array:\n"); for(i=0;i<N;I++) printf("%3d",a[i]): printf("\n\n"); } |
查看答案 |
简答题 | 请补充main()函数,该函数的功能是:先以只写方式打开文件file.dat,再把字符串S中的字符保存到这个磁盘文件中。请勿改动main()函数与其他函数中的任何内容,仅在的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 试题程序: #include #include #define N 100 void main() { FILE*f: int i=0: char ch; char s[N]="Welcome!"; if((f=fopenl("【1】","w"))==NULL) { printf("cannot open file.dat\n"); exit(0); } while(s[i]) { ch=s[i]; 【2】 ; putchar(ch); i++: } 【3】 ; } |
查看答案 |
简答题 | 下列给定程序中,函数ptoc()的功能是:利用插入排序法对字符串中的字符按从小到大的顺序进行排序。插入法的基本方法是:先对字符串中的头两个元素进行排序,然后把第3个字符插入前两个字符中,插入后前3个字符依然有序;再把第4个字符插入前三个字符中,待排序的字符串已 在主函数中赋予。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include #define M 80 void proc(char*arr) { int i,j,n;char ch; n=strlen(arr): for(i=1;i<N;I++) //****found**** { c=arr[i]; j=i-1; while((j>=o)&&(ch<ARR[J])) { arr[j+1]=arr[j]; j--; } arr[j+1]=ch; } } void main() { char a[M]="QWERTYUIOPASDFGHJKLMNBVCXZ"; printf("The original string:%s\n",a); proc(a); printf("The string after sortin9: %s\n\n",a); } |
查看答案 |
简答题 | 规定输入的字符串中只包含字母和*号。编写函数fun(),其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。 例如,字符串中的内容为“****A*BC*DEF*G ****”,删除后,字符串中的内容应当是“ABCDEFG”。 注意:部分源程序给出如下。 请勿改动maini)函数和其他函数中的任何内容,仅在函数fun()的花括号中填入你编写的若干语句。 试题程序: #include #include void fun(char a) { void main() { char s[81]; print{("Enter a string:\n"); gets(s): fun(S); printf("The string after deleted:\n"); puts(s); } |
查看答案 |
简答题 | 下面程序是计算10个整数中奇数的和及其偶数的和,请填空。 #include main() { int a,b,c,i; a=c=0; for(i=1;i<=10;i++) { scanf(“%d”,&b);canf(“%d”,&b); _________ _________ _________ } printf("偶数的和=%d\n",a); printf("奇数的和=%d\n",c); } |
查看答案 |
简答题 | 编写一个自定义函数,实现求两个实数的平方和 | 查看答案 |
简答题 | 以下程序运行后的输出结果是_________。 main() { char s[ ]="GFEDCBA"; int p=6; while(s[p]!=‘D’) { printf("%c ", p); p=p-1; } } |
查看答案 |
简答题 | 定义一个反映学生信息的结构体,包括学生的姓名,性别,年龄,成绩等。 | 查看答案 |