文档详情

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

发布:2017-07-04约3.24千字共4页下载文档
文本预览下载声明
C语言理论上机考试选择题部分 7、在考生文件夹下,给定程序FILL.C的功能是: 计算N*N矩阵的主对角线元素和副对角线元素之和,并作为函数值返回。(要求:先累加主对角线元素中的值,然后累加副对角线元素中的值。) 例如,若N=3,有下列矩阵: 1 2 3 4 5 6 7 8 9 fun函数首先累加1、5、9,然后累加3、5、7,函数的返回值为30。 #include stdio.h #define N 3 fun(int t[][N], int n) { int i, sum; /************found************/ ___1___; for(i=0; in; i++) /************found************/ sum+=___2___ ; for(i=0; in; i++) sum+= t[i][n-i-1] ; return sum; } main() { int t[][N]={1,2,3,4,5,6,7,8,9},i,j; for(i=0; iN; i++) { for(j=0; jN; j++) printf(%4d,t[i][j]); printf(\n); } printf(The result is: %d\n,fun(t,N)); } 8、在考生文件夹下,给定程序FILL.C的功能是: 打印出1至1000中满足其个位数字的立方等于其本身的所有整数。本题的结果为:1 64 125 216 729。 #include stdio.h main() { int i,g; for(i=1;i1000;i++) { /************found************/ g=i___1___10; /************found************/ if(___2___) printf(%4d,i); } printf(\n); } 9、在考生文件夹下,给定程序FILL.C的功能是: 把数组a(大小为M)中前M-1个元素中的最小值放入a的最后一个元素中 #include stdio.h #define M 11 void main() { int a[M],i; for(i=0;iM-1;i++) scanf(%d,a[i]); a[M-1]=a[0]; /************found************/ for(i=1; ___(1)___;i++) /************found************/ if(___(2)___) a[M-1]=a[i]; printf(Max is %d\n,a[M-1]); } 10、在考生文件夹下,给定程序FILL.C的功能是: 统计一维数组a中素数的个数。 例如:如果数组a的元素为:2,3,5,7,8,9,10,11,12,13, 则程序的输出应为:prime number(s) is(are): 6。 #include math.h #include conio.h #include stdio.h prinum( int a[]) { int count,i,j,k; count = 0; for ( i=0; i10; i++) { k=a[i]-1; for ( j=2; j=k; j++) if (a[i] % j == 0) break; if(j = k+1) count++; } /************found************/ ____(1)____; } void main() { int a[10]={2,3,5,7,8,9,10,11,12,13},n; /************found************/ n = ____(2)____;
显示全部
相似文档