二级c语言
二级C语言是全国计算机等级考试中的一项,是很多非计算机专业朋友需要获得的证书,这里收集大量的二级C语言相关的教程和题目
-
函数fun的功能是:在有n名学生,2门课成绩的结构体数组std中,计算出第1门课程的平均分,作为函数值返回。例如,主函数中给出了4名学生的数据,则程序运行的结果为:第1门课程的平均分是:76.125000。请改正程序中的错误,使它能得出正确的结果。#include <stdio.h> #include <stdlib.h> typedef struct { char num[8]; double score[2]; } STU; double fun(STU std[],int n) { int i; /**********found**********/ double sum; for(i=0; i<n; i++) { /**********found**********/ sum += std[i].score[1]; } return sum/n; } main() { STU std[]={"N1001",76.5,82.0 ,"N1002",66.5,73.0, "N1005",80.5,66.0,"N1006",81.0,56.0}; printf("第1门课程的平均分是:%lf\n", fun(std,4)); system("pause"); }
-
函数fun的功能是:根据所给的年、月、日,计算出该日是这一年的第几天,并作为函数值返回。其中函数isleap用来判别某一年是否为闰年。例如,若输入:200851,则程序输出:2008年5月1日是该年的第122天。请在程序的下划线处填入正确的内容#include <stdio.h> #include <stdlib.h> int isleap(int year) { int leap; leap= (year%4==0 && year%100!=0 || year%400==0); /**********found**********/ return __(1)__; } int fun(int year, int month, int day) { int table[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int days=0,i; for(i=1; i<month; i++) { days=days + table[i]; } /**********found**********/ days=days+__(2)__; if(isleap(year) && month>2) { /**********found**********/ days=days+__(3)__; } return days; } main() { int year, month, day,days; printf("请输入年、月、日:"); scanf("%d%d%d", &year, &month, &day); days = fun(year, month, day); printf("%d年%d月%d日是该年的第%d天\n", year, month, day, days); system("pause"); }
-
请编写函数fun(),其功能是:在形参指针所指的4个整数中找出最大值和最小值,最大的放在a中,最小的放在d中。注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括中的标号处填入所编写的若干语句。#include <stdio.h> #include <stdlib.h> void NONO(); void fun(int *a,int *b,int *c,int *d) { int t; if(1) { 2;3;4; } if(5) { 6;7;8; } if(9) { 10;11;12; } if(13) { 14;15;16; } if(17) { 18;19;20; } if(21) { 22;23;24; } } main() { int a, b, c, d; printf("请输入4个整数:"); scanf("%d %d %d %d",&a,&b,&c,&d); printf("原始顺序:%d,%d,%d,%d\n",a,b,c,d); fun(&a,&b,&c,&d); printf("处理后顺序:%d,%d,%d,%d\n",a,b,c,d); NONO(); } void NONO() {/*本函数用于打开文件,输入数据, 调用函数,输出数据,关闭文件。*/ FILE *rf,*wf; int i, a, b, c, d; rf=fopen("in.dat","r"); wf=fopen("out.dat","w"); for(i=0; i<8; i++) { fscanf(rf,"%d %d %d %d",&a,&b,&c,&d); fun(&a,&b,&c,&d); fprintf(wf,"a=%d,d=%d\n",a,d); } fclose(rf); fclose(wf); system("pause"); }
-
函数fun()的功能是:判断整数n是否是“完数”。当一个数的因子之和恰好等于这个数本身时,就称这个数为“完数"。例如:6的因子包括1、2、3,而6=1+2+3,所以6是完数。如果是完数,函数返回值为1,否则函数返回值为0。数组a中存放的是找到的因子,变量k中存放的是因子的个数。请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。#include <stdio.h> #include <stdlib.h> int fun(int n, int a[], int *k) { int m=0, i, t; t=n; for(i=1; i<n; i++) { if(n%i==0) { a[m]=i; m++; t=t-i; } } /**********found**********/ k=m; /**********found**********/ if(t=0) { return 1; } else { return 0; } } main() { int n, a[10], flag, i, k; printf("请输入一个整数:"); scanf("%d",&n); flag=fun(n,a,&k); if(flag) { printf("%d是完数,其因子是:",n); for(i=0;i<k;i++) { printf(" %d ",a[i]); } printf("\n"); } else { printf("%d不是完数\n",n); } system("pause"); }
-
函数fun()的功能是:在有n个元素的结构体数组std中,查找有不及格科目的学生,找到后输出学生的学号;函数的返回值是有不及格科目的学生人数。例如,主函数中给出了4名学生的数据,则程序运行的结果为:学号:N1002 学号:N1006共有2位学生有不及格科目#include <stdio.h> #include <stdlib.h> typedef struct { char num[8]; double score[2]; /**********found**********/ } __(1)__; int fun(STU std[ ], int n) { int i,k=0; for(i=0; i<n;i++) { /**********found**********/ if(std[i].score[0]<60 __(2)__ std[i].score[1]<60) { k++; printf("学号:%s ",std[i].num); } } /**********found**********/ return __(3)__; } main() { STU std[4]={"N1001",76.5,82.0,"N1002",53.5,73.0, "N1005",80.5,66.0,"N1006",81.0,56.0}; printf("\n共有%d位学生有不及格科目\n", fun(std,4)); system("pause"); }
-
以下叙述中错误的是( )。
-
有以下程序#include <stdio.h> main() { int i; FILE* fp; for (i=0; i<3;i++) { fp = fopen("res.txt", "w"); fputc('K'+ i, fp); fclose(fp); } }程序运行后,在当前目录下会生成一个res.txt文件,其内容是 ( )。
-
以下叙述中正确的是( )。
-
有以下程序:#include <stdio.h> int *f(int *s,int *t) { if(*s < *t)s=t; return s; } main() { int i=3,j=5,*p=&i,*q=&j,*r; r=f(p,q); printf("%d,%d,%d,%d,%d\n",i,j,*p,*q,*r); }程序的运行结果是( )。
-
若有以下程序#include <stdio.h> void sp(int *a) { int b=2; *a = *a * 2; printf("%d,",*a); a=&b; *a = *a * 2; printf("%d,",*a); } main() { int k=3; sp(&k); printf("%d\n",k); }则程序的输出结果是( )。
-
有以下程序#include <stdio.h> int m1(int x,int y) { return x<=y ? x :y; } int m2(int x,int y) { return x<=y ? y :x; } int fun(int a,int b) { return a+b; } main() { int x=2,y=3,z=1; printf("%d\n", fun(m1(x,y),m2(y,z))); }程序的运行结果是( )。
-
以下叙述中正确的是( )。
-
有以下程序#include <stdio.h> int k=5; void f(int *s) { s=&k; } main() { int m=3,*p=&m; f(p); printf("%d,%d\n",m,*p); }程序的运行结果是( )。
-
以下叙述中正确的是( )。
-
设有定义:char p[]={'1','2','3'},*q=p;以下不能计算出一个char型 数据所占字节数的表达式是( )。
-
以下叙述中正确的是( )。
-
以下叙述中正确的是( )。
-
有以下程序#include <stdio.h> main() { int a=1, b=0; for(; a<5;a++) { if(a%2 == 0)break; continue; b += a; } printf("%d \n",b); }程序运行后的输出结果是( )。
-
有以下程序#include <stdio.h> main() { int a=-1, b=-1; for(; ++a;)++b; printf("%d,%d\n", a, b); }程序运行后的输出结果是( )。
-
若有定义:int a; float b;double c;程序运行时输入:1,2,3<回车 >,能把1输入给变量a、2输入给变量b、3输入给变量c的输入语句是 ( )。