收藏 分销(赏)

C语言上机编程题.doc

上传人:pc****0 文档编号:6626202 上传时间:2024-12-17 格式:DOC 页数:31 大小:152.50KB 下载积分:10 金币
下载 相关 举报
C语言上机编程题.doc_第1页
第1页 / 共31页
C语言上机编程题.doc_第2页
第2页 / 共31页


点击查看更多>>
资源描述
include <conio.h> #include <stdio.h> void main() { int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos; //clrscr(); max = a[0]; pos = 0; for ( i=1; i<10; i++) /************found************/ if (max < a[i]) { max = a[i]; /************found************/ pos = i; } printf("The max is: %d ,pos is: %d ", max , pos); } 两个位置全部正确 标准答案 第一个位置: if(maxif(max<=a[i]) if(a[i]>max) if(a[i]>=max) 第二个位置: pos=i; 二、 程序填空题(30分,得分:30分)   在考生文件夹下,给定程序FILL.C的功能是: 从键盘上输入一个数字组成的字符串(字符串长度小于8),将该字符 串转换成一个十进制数。 例如:从键盘上输入12345,则程序运行的结果应当为:n=12345。 请填空,并运行该程序,然后将源程序文件FILL.C提交。 程序有两个空(1)、(2)需要补充完整。并将程序调试出所需的结果。 注意:不要随意改动程序,不得增行或删行,也不得更改程序的结构! 做题情况 源程序文件 #include "stdio.h" #include "string.h" void main() { char s[10]; int i; long int n; //clrscr(); /**************found************/ n=0; scanf("%s",s); for(i=0;i<strlen(s);i++) /**************found************/ n=n*10+(s[i]-48); printf("n=%ld ",n); } 两个位置全部正确 标准答案 第一个位置: n=0; 第二个位置: n=n*10+s[i]-’0’; n=n*10+*(s+i)-’0’; n=n*10+*(i+s)-’0’; n=n*10-’0’+s[i]; n=n*10-’0’+*(s+i); n=n*10-’0’+*(i+s); n=n*10+(s[i]-’0’); n=n*10+(*(s+i)-’0’); n=n*10+(*(i+s)-’0’); n=n*10+(s[i]-48); n=n*10+(*(s+i)-48); n=n*10+(*(i+s)-48); n=n*10-(’0’-*(i+s)); n=n*10-(’0’-s[i]); n=n*10-(’0’-*(s+i)); n=n*10+s[i]-48; n=n*10+*(s+i)-48; n=n*10+*(i+s)-48; n=n*10-48+s[i]; n=n*10-48+*(s+i); 三、 程序设计题(40分,得分:40分)   在考生文件夹下,要求程序PROG.C的功能是: 将一个4位的整数m拆开,然后按相反顺序输出,每输出一位数其后留 2个空格。例如,如果m=1234,则程序的输出结果应为:m=1234,4 3 2 1。 部分源程序存在文件PROG.C中。 请在main( )函数中的/*******begin********/ 与 /********end*********/ 之间填入你编写的若干语句,存盘并运行,直到得出正确结果。请勿改动其它位置的任何内容。 注意:main()函数中的最后一行以及main()函数后面的内容,考生不必阅读,但千万不要对这些内容作任何改动。 运行并调试程序,然后将源程序文件PROG.C提交。 特别提示:必须将计算结果存入变量sum中。 做题情况 源程序文件 #include "stdio.h" #include "math.h" #include "conio.h" #include "stdlib.h" void main() { int m=1234,a,b,c,d; /***********begin***********/ a=m%1230; b=(m%100)/10; c=(m/100)%10;d=m/1000; /************end************/ printf("m=%d,%d %d %d %d ",m,a,b,c,d); NONO(m,a,b,c,d); } NONO( x,a,b,c,d ) int x,a,b,c,d; { FILE *f; f=fopen("D:\exam\11200112\PROGOUT.DAT","w"); fprintf(f,"x=%d: %3d%3d%3d%3d#### ",x,a,b,c,d); fclose(f); } 结果文件 x=1234: 4 3 2 1#### 结果文件正确 标准答案 结果文件包含: x=1234:4321#### 辅助判分源文件包含: %`` 比例:20 /10`` 比例:20 /100`` 比例:10 c=`` 比例:20 <PIXTEL_MMI_EBOOK_2005>1 </PIXTEL_MMI_EBOOK_2005> 求二维数组a中的最大值。 例如,当二维数组a中的元素为: 4 4 34 7 3 12 5 6 5 程序的输出应为:The max is: 34 。 请修改并运行该程序,然后将源程序文件MODI.C提交。 程序中有两处错误,错误都在提示行: /***********found***********/的下面一行,请考生注意。 请改正程序中的错误,使它能得出正确的结果。 注意:程序中的其它地方请考生不要随意改动,不得增行 或删行,也不得更改程序的结构! 做题情况 源程序文件 #include <conio.h> #include <stdio.h> void main() { int a[3][3]={4,4,34,7,3,12,5,6,5},i,j,max; max = a[0][0]; for ( i=0; i<3; i++) for ( j=0; j<3; j++) /************found************/ if (max < a[i][j]) { /************found************/ max =a[i][j]; } printf("The max is: %d ", max); } 两个位置全部正确 标准答案 第一个位置: if(maxif(max<=a[i][j]) if(a[i][j]>max) if(a[i][j]>=max) 第二个位置: max=a[i][j]; 二、 程序填空题(30分,得分:30分)   在考生文件夹下,给定程序FILL.C的功能是: m! 求 Cmn= —————— 之值。 n! * (m-n)! 例如,当m=12,n=2时,程序的输出应为:Cmn is: 66 。请填空,并运行该程序, 然后将源程序文件FILL.C提交。 程序有两个空(1)、(2)需要补充完整。并将程序调试出所需的结果。 注意:不要随意改动程序,不得增行或删行,也不得更改程序的结构! 做题情况 源程序文件 #include <math.h> #include <conio.h> #include <stdio.h> long int fun(int x) {long int s=1; int i; for (i=1;i<=x;i++) s*=i; /************found************/ return s; } void main() { long int m=12,n=2,s1,s2,s3; //clrscr(); s1=fun(m); s2=fun(n); s3=fun(m-n); /************found************/ printf("Cmn is : %ld",s1/(s2*s3)); } 两个位置全部正确 标准答案 第一个位置: returns; return(s); 第二个位置: printf("Cmnis:%ld",s1/s2/s3); printf("Cmnis:%ld",s1/s3/s2); printf("Cmnis:%ld",s1/(s2*s3)); printf("Cmnis:%ld",s1/(s3*s2)); printf("Cmnis:%ld",(s1/(s2*s3))); printf("Cmnis:%ld",(s1/s3/s2)); printf("Cmnis:%ld",(s1/(s3*s2))); printf("Cmnis:%ld",(s1/s2/s3)); 三、 程序设计题(40分,得分:20分)   在考生文件夹下,要求程序PROG.C的功能是: 求3*3矩阵的最大值并输出。 例如,当矩阵为: 1 2 3 4 9 5 7 8 6 则最大值为:9 部分源程序存在文件PROG.C中。 请在fun( )函数中的/*******begin********/ 与 /********end*********/ 之间填入你编写的若干语句,存盘并运行,直到得出正确结果。请勿改动其它位置的任何内容。 注意:main()函数中的最后一行以及main()函数后面的内容,考生不必阅读,但千万不要对这些内容作任何改动。 运行并调试程序,然后将源程序文件PROG.C提交。 做题情况 源程序文件 #include <conio.h> #include <stdio.h> int fun(int a[3][3]) { /***********begin***********/ int i,j,max; for (i=1;i<=3;i++) for (j=1;j<=3;j++) if(a[i][j]>max) max=a[i][j]; /************end************/ } void main() { int a[3][3]={1,2,3,4,9,5,7,8,6}; int i,j,max; // clrscr(); printf("array is: "); for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%5d",a[i][j]); printf(" "); } max=fun(a); printf("Result is: %d ",max); NONO( ); } NONO( ) { FILE *fr,*fw; int i,j,k,m,a[3][3]; fr=fopen("D:\exam\11300117\PROGIN.DAT","r"); fw=fopen("D:\exam\11300117\PROGOUT.DAT","w"); for(i=1;i<=5;i++) { for(j=0;j<3;j++) for(k=0;k<3;k++) { fscanf(fr,"%d",&a[j][k]); fprintf(fw,"%4d",a[j][k]);} fprintf(fw,"Max = %d ",fun(a));} fclose(fr); fclose(fw); } 结果文件 12 13 12 18 7 16 10 17 1Max = 4 15 19 2 8 3 5 1 6 1Max = 4 6 10 9 2 4 5 15 4 1Max = 4 1 16 7 2 18 14 8 6 6Max = 4 8 5 10 9 14 5 13 4 8Max = 4 由于结果文件不正确,辅助判分。 源代码中未含return或 标准答案 结果文件包含: 1213121871610171Max=18 15192835161Max=19 61092451541Max=15 116721814866Max=18 851091451348Max=14 辅助判分源文件包含: =a[`` 比例:20 for`` 比例:20 if`` 比例:10 return`` 比例:20 <PIXTEL_MMI_EBOOK_2005>9 </PIXTEL_MMI_EBOOK_2005> 胡健 16:57:06 #include <conio.h> #include <stdio.h> void main() { long s, t, sl=1; int d; //clrscr(); printf(" Please enter s:"); scanf("%ld", &s); t = 0; while ( s > 0) { d = s%10; /************found************/ if (d%2==0) { t=d * sl + t; sl *= 10; } /************found************/ s = s/10; } printf("The result is: %ld ", t); } 两个位置全部正确 标准答案 第一个位置: if(d%2==0) if(!(d%2)) if(0==d%2) if(!(d%2==1)) if(!(1==d%2)) if(0==(d%2)) if(!((d%2)==1)) if(!(1==(d%2))) 第二个位置: s/=10; s=s/10; 二、 程序填空题(30分,得分:15分)   在考生文件夹下,给定程序FILL.C的功能是: 求两个正整数[m,n]之间所有既能被3整除也能被7整除的整数 之和。 例如:m=1,n=2000,则程序的输出结果应为:Sum is : 95760。 请填空,并运行该程序,然后将源程序文件FILL.C提交。 程序有两个空(1)、(2)需要补充完整。并将程序调试出 所需的结果。 注意:不要随意改动程序,不得增行或删行,也不得更 改程序的结构! 做题情况 源程序文件 #include <math.h> #include <conio.h> #include <stdio.h> main() {int m,n,i,t; long int s=0; //clrscr(); scanf("%d,%d",&m,&n); if( m>n ) { t=m; m=n; n=t;} /************found************/ for (i=m;i<=n;i++) if ( i%3==0 && i%7==0 ) s += i; /************found************/ printf("Sum is :%d ",s ); } 第二个位置错 标准答案 第一个位置: for(i=m;i<=n;i++) for(i=m;i 第二个位置: printf("Sumis:%ld ",s); printf("Sumis:%6ld ",s); 三、 程序设计题(40分,得分:40分)   在考生目录下,要求程序PROG.C的功能是:求一个三位整数m的每位数之和,m的值由键盘输入。 例如,当m=256时,程序的输出结果应为:Result is: 13。 部分源程序存在文件PROG.C中。 请在fun( )函数中的/*******begin********/ 与 /********end*********/ 之间填入你编写的若干语句,存盘并运行,直到得出正确结果。请勿改动其它位置的任何内容。 注意:main()函数中的最后一行以及main()函数后面的内容,考生不必阅读,但千万不要对这些内容作任何改动。 运行并调试程序,然后将源程序文件PROG.C提交。 做题情况 源程序文件 #include <conio.h> #include <stdio.h> int fun(int m) { /***********begin***********/ int m1,m2,m3,s; m1=m%10; m2=m/10%10; m3=m/100; s=m1+m2+m3; return s; /************end************/ } void main() { int m,s; //clrscr(); printf("Enter m : "); scanf("%d",&m); s=fun(m); printf("Result is: %d ",s); NONO( ); } NONO( ) { FILE *fr,*fw; int i,j,k,m; fr=fopen("D:\exam\11300121\PROGIN.DAT","r"); fw=fopen("D:\exam\11300121\PROGOUT.DAT","w"); for(i=1;i<=5;i++) { fscanf(fr,"%d",&m); fprintf(fw,"Sum = %d ",fun(m));} fclose(fr); fclose(fw); } 结果文件 Sum = 8 Sum = 18 Sum = 8 Sum = 14 Sum = 10 结果文件正确 标准答案 结果文件包含: Sum=8 Sum=18 Sum=8 Sum=14 Sum=10 辅助判分源文件包含: %10`` 比例:20 /10`` 比例:20 /100`` 比例:10 return`` 比例:20 `` <PIXTEL_MMI_EBOOK_2005>8 </PIXTEL_MMI_EBOOK_2005> 胡健 16:57:29 例如,当二维数组a中的元素为: 4 4 34 7 3 12 5 6 5 程序的输出应为:The max is: 34 。 请修改并运行该程序,然后将源程序文件MODI.C提交。 程序中有两处错误,错误都在提示行: /***********found***********/的下面一行,请考生注意。 请改正程序中的错误,使它能得出正确的结果。 注意:程序中的其它地方请考生不要随意改动,不得增行 或删行,也不得更改程序的结构! 做题情况 源程序文件 #include <conio.h> #include <stdio.h> void main() { int a[3][3]={4,4,34,7,3,12,5,6,5},i,j,max; max = a[0][0]; for ( i=0; i<3; i++) for ( j=0; j<3; j++) /************found************/ if (max < a[i][j]) { /************found************/ max = a[i][j]; } printf("The max is: %d ", max); } 两个位置全部正确 标准答案 第一个位置: if(maxif(max<=a[i][j]) if(a[i][j]>max) if(a[i][j]>=max) 第二个位置: max=a[i][j]; 二、 程序填空题(30分,得分:15分)   在考生文件夹下,给定程序FILL.C的功能是: 在第一个循环中从键盘上给a数组的前M(M<100)个数组元素依次赋值;在 第二个循环中使a数组前M个元素中的值对称折叠;在最后一个循环中输出 折叠以后的a数组的前M个元素。 例如: 当M为5时,如果从键盘上输入的5个数分别为:1、2、3、4、5时, 输出应为:1 2 3 2 1。 当M为10时,如果从键盘上输入的10个数分别为: 1、2、3、4、5、6、7、8、9、10时, 输出应为:1 2 3 4 5 5 4 3 2 1。 请填空,并运行该程序,然后将源程序文件FILL.C提交。 程序有两个空(1)、(2)需要补充完整。并将程序调试出 所需的结果。 注意:不要随意改动程序,不得增行或删行,也不得更 改程序的结构! 做题情况 源程序文件 #define M 5 void main( ) { int i,a[100],t; //clrscr(); for(i=0;i<M;i++) /**************found************/ a[i]=i /**************found************/ for(i=0;i<=2;i++) a[M-i-1]=a[i]; for(i=0;i<M;i++) printf("%5d",a[i]); printf(" "); } 第一个位置错 标准答案 第一个位置: scanf("%d",&a[i]); scanf("%d",a+i); 第二个位置: for(i=0;ifor(i=0;i<=M/2-1;i++) for(i=0;i<=(M-1)/2;i++) for(i=0;i<5/2;i++) for(i=0;i<=5/2-1;i++) for(i=0;i<=(5-1)/2;i++) for(i=0;i<=2;i++) for(i=0;i<2;i++) for(i=0;i<=1;i++) for(i=0;i<=M/2;i++) 三、 程序设计题(40分,得分:40分)   在考生文件夹下,要求程序PROG.C的功能是: 求两个整数m和n的最大公约数,将求出的最大公约数存入变量t中。 部分源程序存在文件PROG.C中。 请在main( )函数中的/*******begin********/ 与 /********end*********/ 之间填入你编写的若干语句,存盘并运行,直到得出正确结果。请勿改动其它位置的任何内容。 注意:main()函数中的最后一行以及main()函数后面的内容,考生不必阅读,但千万不要对这些内容作任何改动。 运行并调试程序,然后将源程序文件PROG.C提交。 特别提示:必须将结果存入变量t中。 做题情况 源程序文件 #include "stdio.h" #include "math.h" #include "conio.h" #include "stdlib.h" void main() { int m=76,n=40,t,i; /***********begin***********/ i=2; if(m%i==0&&n%i==0) i=i+2; t=i; /************end************/ printf("The Highest Common Divisor of %d and %d is %d ",m,n,t); NONO(m,n,t); } NONO( int m,int n,int t) { FILE *f; f=fopen("D:\exam\11300140\PROGOUT.DAT","w"); fprintf(f,"Maximal Common Divisor Of %d and %d is %d ",m,n,t); fclose(f); } 结果文件 Maximal Common Divisor Of 76 and 40 is 4 结果文件正确 标准答案 结果文件包含: MaximalCommonDivisorOf76and40is4 辅助判分源文件包含: n%`` 比例:20 m%`` 比例:20 ==0`` 比例:10 &&`` 比例:20 `` <PIXTEL_MMI_EBOOK_2005>4 </PIXTEL_MMI_EBOOK_2005> ㄣ乱儛尐蓓 16:57:41 #include <conio.h> #include <stdio.h> sum ( int arr[ ],int n ) { int i,s; s = 0; for ( i=0; i<n; i++) if (arr[i] % 2 == 0) /************found************/ s = s + i; return (s); } void main() { int a[10]={10,4,2,7,3,12,5,34,5,9},i,s; /************found************/ s = sum( a ,2 ); printf("The result is: %d ", s); } 两个位置全部错误 标准答案 第一个位置: s=s+arr[i]; s+=arr[i]; s=arr[i]+s; 第二个位置: s=sum(a,10); 二、 程序填空题(30分,得分:15分)   在考生文件夹下,给定程序FILL.C的功能是: 求两个正整数[m,n]之间所有既能被3整除也能被7整除的整数 之和。 例如:m=1,n=2000,则程序的输出结果应为:Sum is : 95760。 请填空,并运行该程序,然后将源程序文件FILL.C提交。 程序有两个空(1)、(2)需要补充完整。并将程序调试出 所需的结果。 注意:不要随意改动程序,不得增行或删行,也不得更 改程序的结构! 做题情况 源程序文件 #include <math.h> #include <conio.h> #include <stdio.h> main() {int m,n,i,t; long int s=0; //clrscr(); scanf("%d,%d",&m,&n); if( m>n ) { t=m; m=n; n=t;} /************found************/ for (i=1;i<2000;i++) if ( i%3==0 && i%7==0 ) s += i; /************found************/ printf("Sum is : %ld ",s ); } 第一个位置错 标准答案 第一个位置: for(i=m;i<=n;i++) for(i=m;i 第二个位置: printf("Sumis:%ld ",s); printf("Sumis:%6ld ",s); 三、 程序设计题(40分,得分:40分)   在考生文件夹下,要求程序PROG.C的功能是: 将一个4位的整数m拆开,然后按相反顺序输出,每输出一位数其后留 2个空格。例如,如果m=1234,则程序的输出结果应为:m=1234,4 3 2 1。 部分源程序存在文件PROG.C中。 请在main( )函数中的/*******begin********/ 与 /********end*********/ 之间填入你编写的若干语句,存盘并运行,直到得出正确结果。请勿改动其它位置的任何内容。 注意:main()函数中的最后一行以及main()函数后面的内容,考生不必阅读,但千万不要对这些内容作任何改动。 运行并调试程序,然后将源程序文件PROG.C提交。 特别提示:必须将计算结果存入变量sum中。 做题情况 源程序文件 #include "stdio.h" #include "math.h" #include "conio.h" #include "stdlib.h" void main() { int m=1234,a,b,c,d; /***********begin***********/ a=m%10; b=(m/10)%10; c=(m/100)%10; d=(m/1000)%10; /************end************/ printf("m=%d,%d %d %d %d ",m,a,b,c,d); NONO(m,a,b,c,d); } NONO( x,a,b,c,d ) int x,a,b,c,d; { FILE *f; f=fopen("D:\exam\11200127\PROGOUT.DAT","w"); fprintf(f,"x=%d: %3d%3d%3d%3d#### ",x,a,b,c,d); fclose(f); } 结果文件 x=1234: 4 3 2 1#### 结果文件正确 标准答案 结果文件包含: x=1234:4321#### 辅助判分源文件包含: %`` 比例:20 /10`` 比例:20 /100`` 比例:10 c=`` 比例:20 `` <PIXTEL_MMI_EBOOK_2005>2 </PIXTEL_MMI_EBOOK_2005> #include <conio.h> #include <stdio.h> void main() { int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos; //clrscr(); max = a[0]; pos = 0; for ( i=1; i<10; i++) /************found************/ if (max < a[i]) { max = a[i]; /************found************/ pos=i; } printf("The max is: %d ,pos is: %d ", max , pos); } 两个位置全部正确 标准答案 第一个位置: if(maxif(max<=a[i]) if(a[i]>max) if(a[i]>=max) 第二个位置: pos=i; 二、 程序填空题(30分,得分:1分)   在考生文件夹下,给定程序FILL.C的功能是: 输出Fabonacci数列:1,1,2,3,5,8,……的前20项的 项值,要求每行输出5个数。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服