文档详情

计算机二级C语言100套上机操作题及答案..doc

发布:2017-01-20约20.45万字共226页下载文档
文本预览下载声明
C语言上机操作题 内 部 资 料 .第1套 填空题 请补充FUN函数,FUN函数的功能是求10的阶乘。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容, 仅在fun函数的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h long fun(int n) { if (___1___) return (n*fun(___2___)); return ___3___; } main() { printf(10!=%ld\n, fun(10)); } 第1处填空:n1或1n 第2处填空:n-1 第3处填空:1或11或1L 改错题 下列给定程序的功能是:读入一个整数K(2〈=K〈=10000),打印它的所有因子(即所有为素数的因子)。例如,若输入整数2310,则应输出:2、3、5、7、11。 请改正程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include conio.h #include stdio.h /********found********/ IsPrime(int n); { int i, m; m = 1; /********found********/ for (i=2; in; i++) if !(n%i) { m = 0; break; } return(m); } main() { int j, k; printf(\nplease enter an integer number between 2 and 10000:); scanf(%d, k); printf(\n\nThe prime factor(s) of %d is(are):, k); for (j=2; jk; j++) if ((!(k%j)) (IsPrime(j))) printf( %4d,, j); printf(\n); } 第1处:Isprime(int n);应改为Isprime(int n) 第2处:if !(n%i)应该为if(!(n%i)) 编程题 M个人的成绩存放在score数组中,请编写函数fun,它的功能是:返回低于平均分的认输,并将低于平均分的分数放在below所指的数组中。 例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的认输应该是4,below中的数据应我10、20、30、40。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include conio.h #include stdio.h #include string.h int fun(int score[],int m, int below[]) { } main() { int i,n,below[9]; int score[9]={10,20,30,40,50,60,70,80,90}; FILE *out; n=fun(score,9,below); printf(\nBelow the average score are :); out=fopen(out.dat, w); for(i=0;in;i++) { printf(%d ,below[i]); fprintf(out, %d\n, below[i]); } fclose(out); } 答案是: int fun(int score[], int m, int below[]) { int I, k=0,aver=0; for(i=0;im;i++) aver+=score[i]; aver/=m; for(i=0;im;i++) if(score[i]aver) { below[k]=score[i]; k++; } return k; } 第2套 填空题 请在函数FUN的横线上填写若干表达式,使从键盘上输入一个整数N,输出斐波纳契数列。斐波纳契数列是一种整数数列,其中每数等于前面两数之和,如:0 1 1 2 3 5 8 13….. 请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。 试题程序: #include stdio.h int fun(int n); main() { int i, n = 0; scanf(%d,
显示全部
相似文档