考试.docx
- 文档编号:15980940
- 上传时间:2023-07-09
- 格式:DOCX
- 页数:21
- 大小:57.83KB
考试.docx
《考试.docx》由会员分享,可在线阅读,更多相关《考试.docx(21页珍藏版)》请在冰点文库上搜索。
考试
#include
#include
voidmain()
{inta[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 { max=a[i]; /************found************/ pos=i; } printf("Themaxis: %d,posis: %d\n",max,pos); } #include"stdio.h" #include"math.h" #include"conio.h" #include"stdlib.h" voidmain() {intm=1234,a,b,c,d; /***********begin***********/ a=m%10; b=(m-a)%100/10; c=(m-a-b)%1000/100; d=m/1000; /************end************/ printf("m=%d,%d%d%d%d\n",m,a,b,c,d); NONO(m,a,b,c,d); } NONO(x,a,b,c,d) intx,a,b,c,d; {FILE*f; f=fopen("D: \\exam\\05910227\\PROGOUT.DAT","w"); fprintf(f,"x=%d: %3d%3d%3d%3d####\n",x,a,b,c,d); fclose(f); } #include"stdio.h" voidmain() {longintf[20]={1,1}; inti; //clrscr(); /**************found************/ printf("%8ld%8ld",f[0],f[1]); for(i=2;i<20;i++) { f[i]=f[i-1]+f[i-2]; /**************found************/ if(i%5==0)printf("\n"); printf("%8ld",f[i]); } printf("\n"); } #include #include #include voidmain() {inta[10]={2,3,5,7,8,9,10,11,12,13},i,j,k,count; //clrscr(); count=0; for(i=0;i<10;i++) { k=sqrt(a[i]); for(j=2;j if(a[i]%j==0&&a[i]%1==0) break; /************found************/ if(j==k) count++; } /************found************/ printf("primenumber(s)is(are): %d",count); } 1.在考生目录下,给定程序FILL1.C的功能是: 计算正整数num的各位上的数字之积。 例如,若输入: 252,则输出应该是: 20。 若输入: 202,则输出应该是: 0。 #include #include main( ) {long int num,k; /************found************/ k=1; 2. clrscr() ; printf("\Please enter a number: ") ; scanf("%ld",&num) ; do { k*=num%10 ; /************found************/ num=num/10; } while(num) ; printf("\n%ld\n",k) ; } 2. 在考生目录下,给定程序FILL1.C的功能是: 从键盘上 输入一个数字组成的字符串(字符串长度小于8),将该字 符串转换成一个十进制数。 例如: 从键盘上输入12345,则程序运行的结果应当为: n=12345。 #include "stdio.h" main() { char s[10]; int i; long int n=0; clrscr(); /**************found************/ gets(s); /**************found************/ for(i=0;s[i]! =’\0’;i++) n=n*10+s[i]-'0'; printf("n=%ld\n",n); } 或者scanf(“%s”,s) 3. 在考生目录下,给定程序FILL1.C的功能是: 输出 Fabonacci数列: 1,1,2,3,5,8,……的前20项的 项值,要求每行输出5个数。 请填空。 #include "stdio.h" main() { long int f[20]={1,1}; int i; clrscr(); /**************found************/ printf(“%8ld%8ld”,f[0],f[1]); for(i=2;i<20;i++) { f[i]=f[i-1]+f[i-2]; /**************found************/ if(i%5==0) printf("\n"); printf("%8ld",f[i]); } printf("\n"); } 4. 在考生目录下,给定程序FILL1.C的功能是: 实现在N行M列 的二维数组中,找出每一行上的最大值,且原数组值不变。 例如: 如果二维数组元素的值为: 1 5 7 4 2 6 4 3 8 2 3 1 时,程序的运行结果应为: The max value in line 0 is 7 The max value in line 1 is 6 The max value in line 2 is 8 #define M 4 #define N 3 main() { int i,j,p,x[N][M]={1,5,7,4,2,6,4,3,8,2,3,1}; clrscr(); /************found************/ for(i=0;i { p=0; for(j=0;j if(x[i][p] /************found************/ p=j; printf("The max value in line %d is %d\n",i,x[i][p]); } } 5. 在考生目录下,给定程序FILL1.C的功能是: 将无符号 八进制数字构成的字符串转换为十进制整数。 例如,输入的字符串为: 556,则输出十进制整数366。 请填空。 #include main() { char s[6]; int n=0,j=0; clrscr(); /************found************/ scanf(“%s”,s); /************found************/ while(s[j]! =’\0’) { n=n*8+s[j]-'0'; j++; } printf("%d\n",n); } 7. 在考生目录下,给定程序FILL1.C的功能是: 计算1到100 之间的奇数之和及偶数之和。 请填空。 #include main() { int a,b,c,i; clrscr(); /**************found************/ a=0,c=0; for(i=0;i<=100;i+=2) { a+=i; /**************found************/ b=i+1; c+=b; } printf("sum of evens is %d\n",a); printf("sum of odds is %d\n",c-101); } 8. 在考生目录下,输出一维数组a中的最小值及其下标。 #include main( ) { int i,p=0,a[10]; clrscr(); /************found************/ for(i=0;i<10;i++) scanf("%d",&a[i]); for(i=1;i<10;i++)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 考试