c语言上机字符串,二级C语言上机题库100套(最新)

《二级C语言上机题库100套(最新)》由会员分享,可在线阅读,更多相关《二级C语言上机题库100套(最新)(314页珍藏版)》请在人人文库网上搜索。

1、2010年上半年上机题库国家计算机等级考试二级C语言2010年上半年上机题库目 录【填空】3【计算】3【结构体、学生编号】14【矩阵】21【链表】26【其他】33【数组】38【填空】48【字符串】120【最值、排序】144【改错】150【字符串】150【整除】170【找大小】171【找0】172【素数】173【数组】176【删除】182【三角】183【奇偶】185【链表】190【交换、转换】194【积】197【公约公倍】197【公式】199【改错】208【编程】274【被除数、素数】274【公式求值】277【矩阵、数组】285【删除字母】290【学生成绩】299【字符串】305【最值】312【。

2、填空】【计算】26.下列给定程序中,函数fun的功能是:找出100999之间(含100和999)所有整数中各位上数字之和为x(x为正整数)的整数,并输出;符合条件的整数个数作为函数值返回。例如,当x值为5时,100999之间各位上数字之和为5的整数有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500,共有15个。当x值为27时,各位数字之和为27的整数是:999,只有1个。#include int fun(int x) int n, s1, s2, s3, t;n=0;t=100;/*found*/while(t0): );。

3、 scanf(%d,&x); printf(nThe result is: %dn,fun(x);31.下列给定程序中,函数fun的功能是:计算下式前n项的和,并作为函数值返回。例如,若主函数从键盘给n输入50后,则输出为S=1.960784。#include double fun(int n)int i,j;double sum=0.0,t;for(i=1;i#include int fun(char *fname ) FILE *fp; int i,n; float x;if(fp=fopen(fname, w)=NULL) return 0;for(i=1;iint fun(int x)。

4、 int n, s1, s2, s3, t;/*found*/n=0;t=100;/*found*/while(t999|xdouble fun( double r)return 3.14159*r*r/2.0;void main()double x;printf(Enter x: );scanf(%lf,&x);printf(s=%lfn,fun(x);57.请补充main函数,该函数的功能是:计算两个自然数n和m(m#include #include void main()int n,m;long sum;sum=0;system(CLS);printf(nInput n,mn);scan。

5、f(%d,%d,&n,&m);while(n#include #include int fun(int n)int flag=0;if(n%4=0)if (n%100)flag=1;if (n%400=0)flag=1;return flag;void main()int year;system(CLS);printf(Input the year:);scanf(%d,&year);if (fun(year)printf(%d is a leap year. n,year);elseprintf(%d is not a leap year.n,year);61.给定程序的功能是:计算scor。

6、e中m个人的平均成绩aver,将低于aver的成绩放在below中,并返回人数。例如,当score10,20,30,40,50,60,70,80,90,m9时,函数返回的人数应该是4,below10,20,30,40#include #include int fun(int score,int m, int below)int i,j=0;float aver =0.0;for(i=0;iint c1,c2,c3;void fun(long n)c1=c2=c3=0;while(n)switch(n%10)case 1:c1+;break;case 2:c2+;break;case 3: c3。

7、+;n/=10;main()long n=123114350L;fun(n);printf(nThe result: n);printf(n=%ld c1=%d c2=%d c3=%dn,n,c1,c2,c3); 63.请补充函数fun,该函数的功能是:整除x且是偶数的数,把这些数保存在数组bb中,并按从大到小的顺序输出。例如当x20时,依此输出:201042。#include #include #include void fun(int k,int bb)int i;int j=0;for(i=1;i=0;i-)printf(%d ,bbi);void main()int k=1;int b。

8、b100;system(CLS);printf(nPlease input X=);scanf(%d,&k);fun(k,bb);67.请补充main函数,该函数的功能是:求n!。例如,7!5040。#include #include #include void main()int i,n;long f=1;system(CLS);printf(Input n: );scanf(%d,&n);for(i=1;ilong fun(int n)int i;long s;s=1;for(i=1;idouble fun(double q) int n;double s,t;n=2;s=2.0;whil。

9、e(s#include void main()int i, n;long s=0, t=1;system(CLS);printf(nInput n:n);scanf(%d,&n);for(i=1;iint fun(int n);void main()int i,n=0;scanf(%d,&n);for(i=0;i#include #include char *fun(int n)int g,s,b;g=n%10;s=n/10%10;b=n/100%10;if(g+b)=s)return yes!;elsereturn no!;void main()int num=0;system(CLS);p。

10、rintf(*Input data *n);scanf(%d,&num);printf(nnn);printf(* The result *n);printf(nnn%s,fun(num);91.请补充main函数,该函数的功能是:计算每个学生成绩的平均分,并把结果保存在数组bb中。例如,当scoreNM83.5,82,86,65,67,80,91.5,84,99,95,90.5,95,86,95,97时,三个学生的平均分为76.7,89.9,92.7。#include #define N 3#define M 5void main()int i,j;static float scoreNM=。

11、83.5,82,86,65,67,80,91.5,84,99,95,90.5,95,86,95,97;float bbN;system(CLS);for(i=0;i#include #include double fun(double x10)int i;long t;double avg=0.0;double sum=0.0;for(i=0;i#include #include void main()float a,b,c, disc,x1,x2;system(CLS);doprintf(Input a,b,c:);scanf(%f,%f,%f,&a,&b,&c);disc=b*b-4*a*。

12、c;if(disc#include struct student long sno;char name10;float score3;void fun(struct student a) struct student b; int i;/*found*/b = a;b.sno = 10002;/*found*/strcpy(b.name, LiSi);printf(nThe data after modified :n);printf(nNo: %ld Name: %snScores: ,b.sno, b.name);/*found*/for (i=0; i#include struct st。

13、udent long sno;char name10;float score3;/*found*/struct student * fun(struct student *a) int i;a-sno = 10002;strcpy(a-name, LiSi);/*found*/for (i=0; iscorei += 1;/*found*/return a ;main() struct student s=10001,ZhangSan, 95, 80, 88, *t;int i;printf(nnThe original data :n);printf(nNo: %ld Name: %snSc。

14、ores: ,s.sno, s.name);for (i=0; isno, t-name);for (i=0; iscorei);printf(n);27.程序通过定义学生结构体变量,存储学生的学号、姓名和3门课的成绩。函数fun的功能是:对形参b所指结构体变量中的数据进行修改,并在主函数中输出修改后的数据。例如,若b所指变量t中的学号、姓名和三门课的成绩依次是:10002、ZhangQi、93、85、87,修改后输出t中的数据应为:10004、LiJie、93、85、87。#include #include struct student long sno;char name10;float 。

15、score3;void fun( struct student *b)/*found*/b-sno = 10004;/*found*/strcpy(b-name, LiJie);main() struct student t=10002,ZhangQi, 93, 85, 87;int i;printf(nnThe original data :n);printf(nNo: %ld Name: %snScores: ,t.sno, t.name);for (i=0; i#define N 5typedef struct student long sno;char name10;float sco。

16、re3; STU;void fun(char *filename, long sno) FILE *fp;STU n; int i;fp = fopen(filename,rb+);/*found*/while (!feof(fp) fread(&n, sizeof(STU), 1, fp);/*found*/if (n.sno=sno) break;if (!feof(fp) for (i=0; i#include struct student long sno;char name10;float score3;/*found*/struct student fun(struct stude。

17、nt a) int i;a.sno = 10002;/*found*/strcpy(a.name, LiSi);/*found*/for (i=0; i#include #define N 5typedef struct int num;char name10;char tel10;STYPE;void check();/*found*/int fun(STYPE *std)/*found*/FILE *fp; int i;if(fp=fopen(myfile5.dat,wb)=NULL)return(0);printf(nOutput data to file !n);for(i=0; i#。

18、include struct student long sno;char name10;float score3;void fun(struct student a, int n)/*found*/struct student t;int i, j;/*found*/for (i=0; i 0) t = ai; ai = aj; aj = t; main() struct student s4=10001,ZhangSan, 95, 80, 88,10002,LiSi, 85, 70, 78,10003,CaoKai, 75, 60, 88, 10004,FangFang, 90, 82, 8。

19、7;int i, j;printf(nnThe original data :nn);for (j=0; j#include #define N 8typedef structchar num10;int year,month,day;STU;STU fun(STU *std,char *num)int i;STU a=,9999,99,99;for(i=0;i#define N 4void fun(int (*t)N, int m) int i, j;/*found*/for(i=0; i=0; j-)/*found*/tij+m=tij;/*found*/for(j=0; j#define N 4void fun(int (*t)N) int j ,rN;for(j=0; j=0;j-)tN-1N-1-j=tjN-1;for(j=N-1; j=0; j-)/*found*/tjN-1=rj;main() int tN=21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10, i, j;printf(nThe original array:n);for(i=0; iN; i+) for(j=0; jN; j+) printf(%2d ,tij);printf(n);fun(t);printf(nThe。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值