2016C语言理论上机考试程序填空题03.docVIP

  • 114
  • 0
  • 约1.73千字
  • 约 2页
  • 2017-07-05 发布于江西
  • 举报
2016C语言理论上机考试程序填空题03

C语言理论上机考试选择题部分 13、在考生文件夹下,给定程序FILL.C的功能是: 求一维数组a中非素数之和。 例如:如果数组a的元素为:2,3,5,7,8,9,10,11,12,13,15,17, 则程序的输出应为:Sum is: 54。 #include math.h #include conio.h #include stdio.h void main() { int a[12]={2,3,5,7,8,9,10,11,12,13,15,17},i,j,k,s; /************found************/ ____(1)____; for ( i=0; i12; i++) { k=sqrt(a[i]); for ( j=2;j = k; j++) if (a[i] % j == 0) break; if( j=k ) /************found************/ s=s+____(2)____; } printf(Sum is: %d\n,s); } 14、在考生文件夹下,给定程序FILL.C的功能是: 查找n在数组a中最后一次出现的位置(数组首元素的位置为零)。 例如:如果a数组中的元素为:1,5,2,5,6,8,7,4,3,0, 当n=5时,程序的输出结果为:5 is No.3 。 当n=10时,程序的输出结果应为:10 not found !。 #include stdio.h void main( ) { int a[10]={1,5,2,5,6,8,7,4,3,0}; int i,k,n,f=0; scanf(%d,n); for(i=0;i10;i++) /************found************/ if(___(1)___) { f=1; /************found************/ ___(2)___; } if(f) printf(%d is No. %d\n, n,k); else printf( %d not found !\n,n); } 15、在考生文件夹下,给定程序FILL.C的功能是: 求两个正整数x,y的最大公约数和最小公倍数。 例如:如果x=24,y=36,程序的输出应为: max is : 12 min is : 72 。 #include math.h #include conio.h #include stdio.h void main() { int x,y,t,max,min,i,n1,n2; printf(Please enter two numbers:); scanf(%d,%d,x,y); if(x y) {t = x; x = y; y = t;} n1=x; n2=y; t = n2 % n1; /************found************/ while( ____(1)____ ) { n2 = n1 ; n1 = t ; t = n2 % n1; } /************found************/ max = ____(2)____ ; min = x * y / max ; printf(max is : %d\n,max); printf(min is : %d\n,min); } 2 s=0; s=s+a[i]; if(a[i]==n) k=i; while(t!=0) max=n1;

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档