使用说明:
此100套编程题来源于清华同方光盘电子出版的《全国计算机等级考试二级C语言程序设计上机考试题库》,特此声明。
国二考试二级C语言程序设计100套题,各个版本的书大概都差不多。以下是本人精心整理的题库100题(包括答案以及题目要求),希望给悉心复习的你一点小小的启发和帮助啦。因为写得匆忙,如果有不恰当之处,恳请各路编程高手给予批评指正(本人纯属业余的编程爱好者)!
注:答案仅供参考!!
——作者
100套题第1套编程题
#include
#define M 100
void fun (int m,int *a,int *n)
{
int i;*n=0;
for(i=1;i<=m;i++)
if(i%7==0||i%11==0)
a[(*n)++]=i;
}
main( )
{ int aa[M],n,k;
fun(50,aa,&n);
for(k=0;k if((k+1)%20==0) printf("\n"); else printf("%4d",aa[k]); printf("\n") ; } 题目要求: 将1~m之间能被7或11整除的所有整数放入数组a,通过n返回数的个数。如m=50,则程序输出:7 11 14 21 22 28 33 35 42 44 49. 100套题第2套编程题 #include void fun( int m, int *k, int xx[] ) { int i,j,t=0; for(i=4;i {for(j=2;j if(i%j==0) {xx[t++]=i;break;}} *k=t; } main() { int m, n, zz[100]; printf( "\nPlease enter an integer number between 10 and 100: " ); scanf( "%d", &n ); fun( n, &m, zz ); printf( "\n\nThere are %d non-prime numbers less than %d:", m, n ) ; for( n = 0; n < m; n++ ) printf( "\n %4d", zz[n] ); } 题目要求: 将所有大于1小于整数m的非素数存入xx数组,其个数通过k返回。 100套题第3套编程题 #include #include #define N 16 typedef struct { char num[10]; int s; } STREC; STREC fun( STREC *a, char *b ) { int i; STREC str={"\0",-1}; for(i=0;i if(strcmp(a[i].num,b)==0) str=a[i]; return str; } main() { STREC s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85}, {"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87}, {"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91}, {"GA011",77},{"GA017",64},{"GA018",64},{"GA016",72}}; STREC h; char m[10]; int i;FILE *out ; printf("The original data:\n"); for(i=0; i { if(i%4==0) printf("\n"); printf("%s %3d ",s[i].num,s[i].s); } printf("\n\nEnter the number: ");gets(m); h=fun( s,m ); printf("The data : "); printf("\n%s %4d\n",h.num,h.s); printf("\n"); out = fopen("out.dat","w") ; h=fun(s,"GA013"); fprintf(out,"%s %4d\n",h.num,h.s); fclose(out); } 题目要求: 学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中,编写函数fun,功能是:函数返回该学号的学生数据,指定的学号在主函数中输入。若没找到则给学号置空串,给成绩置-1,作为函数值返回(用于字符串比较的函数是strcmp)。 100套题第4套编程题 #include #include double fun(int m) { int i; double s=0.0; for(i=1;i<=m;i++) s+=log(i); return sqrt(s); } main() { printf("%f\n", fun(20)); } 题目要求: 计算下列式子的函数值:s=(ln(1)+ln(2)+ln(3)+…+ln(m))0.5,并返回s的值。 可调用log(n)函数求ln(n)。如m值为20,则函数值为6.506583. 100套题第5套编程题 #include #include