(完整版)C语言考试题库及答案 联系客服

发布时间 : 星期六 文章(完整版)C语言考试题库及答案更新完毕开始阅读61c142ccbbd528ea81c758f5f61fb7360b4c2b82

5、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中所有元素的平均值。

例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 程序的输出应为:The aver is: 9.10 。

#include #include void main() {

int a[10]={10,4,2,7,3,12,5,34,5,9},i; double aver,s; s = a[0];

/************found************/ for ( i=1; i<10; i++) for ( i=0; i<10; i++)

/************found************/ s = s + i; s = s + a[i]; aver = s / i;

printf(\}

6、在考生文件夹下,给定程序MODI.C的功能是: 输入一个百分制成绩,打印出五级记分成绩。考试成绩在90分或90分以上为优秀,80~89分为良好,70~79为中等,60~69为及格,低于60分为不及格。

#include #include #include #include void main() {

int score,t;

printf(\ do

{scanf(\ while(score<0||score>100); t=score/10;

/*************found**************/ switch(t) switch(score)

{

case 10:

case 9:printf(\优秀!\\n\ case 8:printf(\良好!\\n\ case 7:printf(\中等!\\n\ case 6:printf(\及格!\\n\

/*************found**************/ else :printf(\不及格!\\n\ } default: printf(\不及格!\\n\} 7、在考生文件夹下,给定程序MODI.C的功能是: 输出100~200之间既不能被3整除也不能被7整除的整数并统计这些整数的个数,要求每行输出8个数。

#include #include #include #include void main() {

int i;

/************found************/ int n; int n=0; for(i=100;i<=200;i++) {

/************found************/ if(i%3==0&&i%7==0) { if(n%8==0) printf(\

printf(\if(i%3!=0 && i%7!=0) n++; } }

printf(\}

8、在考生文件夹下,给定程序MODI.C的功能是: 学习优良奖的条件如下:所考5门课的总成绩在450分(含)以上;或者每门课都在88分(含)以上。输入某学生5门课的考试成绩,输出是否够学习优良奖的条件。

#include main() {

int score,sum=0; int i,n=0;

for(i=1;i<=5;i++)

{ scanf(\ sum+=score;

/************found************/ if(score>=88) n++; if(score<=88) n++;

}

/************found************/ if(sum>=450 && n==5 ) if(sum>=450 || n==5 ) printf(\ good!\\n\ else

printf(\ }

- 21 -

9、在考生文件夹下,给定程序MODI.C的功能是: 输出200~300之间的所有素数,要求每行输出8个素数。

#include #include main() {

int m,j,n=0,k;

for(m=200;m<=300;m++) {

k=sqrt(m);

for(j=2;j<=k;j++)

/************found************/ if(m%j==0) continue; if(m%j==0) break; if(j>k)

{ if(n%8==0) printf(\ /************found************/ printf(\printf(\ n++; ; } } }

10、在考生文件夹下,给定程序MODI.C的功能是: 求出a所指数组中最小数(规定最小数不在a[0]中),最小数和a[0]中的数对调。

例如数组中原有的数为:7、10、12、0、3、6、9、11、5、8,

输出的结果为:0、10、12、7、3、6、9、11、5、8。

#include #include #define N 20 main( ) {

int a[N]={7,10,12,0,3,6,9,11,5,8}, n=10, i, k,m,min,t; for ( i = 0; i

min= a[0]; m=0;

for ( k = 0; k < n; k++ )

/************found************/ if ( a[k]>min ) if(a[k]

min = a[k]; m = k; }

/************found************/ t = a[0]; a[m]=a[0]; a[m] = t;

for ( i=0; i

求一维数组a中的最小元素及其下标。

例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9, 程序的输出应为:The min is: 1,pos is: 0 。

#include #include main()

{ int a[10]={1,4,2,7,3,12,5,34,5,9},i,min,pos; /************found************/ min = 0;

min=a[0]; pos = 0;

for ( i=1; i<10; i++) if (min > a[i]) { min = a[i];

/************found************/ pos = a[i]; pos=i; }

printf(\}

12、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中值为偶数的元素之和。 例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 , 程序的输出应为:The result is: 62。

#include #include sum ( int arr[ ],int n ) {

int i,s; s = 0;

for ( i=0; i

/************found************/ s = s + i; s=s+arr[i]; return (s); }

void main() {

int a[10]={10,4,2,7,3,12,5,34,5,9},s; /************found************/ s=sum(a,10); sum( a ,2 );

printf(\ }

- 22 -

13、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中的最大元素及其下标。

例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9, 程序的输出应为:The max is: 34,pos is: 7 。

#include #include void main()

{ int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos; max = a[0]; pos = 0;

for ( i=1; i<10; i++)

/************found************/ if (max > a[i]) if(max

/************found************/ max = a; max=a[i]; pos =i; }

printf(\ }

14、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中值为奇数的元素之和。

例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9, 21 ,19

程序的输出应为:The result is: 69。

#include #include int sum( int b[ ],int n ) {

int i,s = 0;

for ( i=0; i

/************found************/ s = s + b[i] s=s+b[i]; return (s); }

main() {

int a[12]={10,4,2,7,3,12,5,34,5,9,21,19},n; /************found************/ sum(a,2);

sum(a,12); printf(\ }

15、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中的最大元素及其下标。

例如,当一维数组a中的元素为:34,4,2,7,3,12,5,8,5,9, 程序的输出应为:The max is: 34,pos is: 0 。

#include #include int max;

maxarr(int arr[ ]) {

int pos,i;

/************found************/ max = 0;

pos = 0;

max=arr[0]; for ( i=1; i<10; i++) if (max < arr[i]) { max = arr[i]; pos = i; }

/************found************/ return (i); return(pos); } main() {

int a[10]={34,4,2,7,3,12,5,8,5,9};

printf(\ }

- 23 -

程序填空题(共15题)

1、在考生文件夹下,给定程序FILL.C的功能是: 求二分之一的圆面积,函数通过形参得到圆的半径,函数返回二分之一的圆面积(注意:圆面积公式为:S=3.14159*r*r,在程序中定义的变量名要与公式的变量相同)。例如,输入圆的半径值:2.5,输出为s=9.817469。

#include

/************found************/ double fun ( float ___1___ ) double fun ( float r) {

return 3.14159 * r*r/2.0 ; }

main() {

float x;

printf ( \ x: \

/************found************/ scanf ( \

scanf ( \ printf (\ }

2、在考生文件夹下,给定程序FILL.C的功能是: 计算并输出下列级数的前n项之和Sn,直到Sn大于q为止,q的值通过形参传入。

Sn = 2/1 + 3/2 + 4/3 + …… + (n+1)/n

例如,若q的值为50.0,则函数值为50.416691。

#include float fun( float q ) {

int n; float s; n = 2; s = 2.0;

/************found************/ while (s___1___q) while(s<=q) {

s=s+(float)(n+1)/n;

/************found************/ ___2___; }

n++; return s; }

main() {

printf(\ }

3、在考生文件夹下,给定程序FILL.C的功能是:

统计整数n的各个位上出现数字1、2、3的次数,并通过外部(全局)变量c1、c2、c3返回主函数。 例如,当n=123114350时,结果应该为:c1=3 c2=1 c3=2。

#include int c1,c2,c3; void fun(long n) {

c1 = c2 = c3 = 0; while (n) {

/************found************/

switch(___1___) switch(n) {

case 1: c1++; break; /************found************/ case 2: c2++;___2___; case 3: c3++;

break; }

n /= 10; } }

main() {

int n=123114350; fun(n);

printf(\

4、在考生文件夹下,给定程序FILL.C的功能是:

程序的功能是计算y = 0! + 1! + 2! + 3! + 4! + …… + n! 如输入n的值为5的话,则输出y值为154 #include int fun(int n) {

int i; int s; s=1; for (i=1; i<=n; i++)

/************found************/ s=___1___; s=s*i; return s; }

main() {

int s; int k,n;

scanf(\ s=0; for (k=0; k<=n; k++)

/************found************/ s=___2___; s=s+fun(k); printf(\ }

- 24 -