二级C语言题库2.pdf
《二级C语言题库2.pdf》由会员分享,可在线阅读,更多相关《二级C语言题库2.pdf(76页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、二级C 语言题库第 21套题一、程序填空题#include<stdio.h>ini fun(inl x)int n,si,s2,s3,t;/*found*不*/n=_ 1_;t=100;/*字 不 *sjjfou nd*字/while(t<=2)sl=t%10;s2=(t/10)%10;s3=t/100;if(sl+s2+s3=15)printf("%d",t);n+;)/*found*/_ 3 _;)return n;)main()int x=l;while(x>999llx<0)printf("Please input(0<
2、x<=999):");scanf("%d",&x);printf("nThe result is:%dn",fun(x);)二、程序改错题#include<stdio.h>#include<string.h>void fun(char*s,char*t)/*不*字 found*/int i;si=strlen(s);for(i=0;i<sl;i+)/*字 不*fou nd*字 孝 孝 字*/ti=ssl-i;for(i=0;i<sl;i+)tsl+i=si;t2*sl=A0,;)main()ch
3、ar s100,t100;printf("nPlease enter string s:");scanf("%s",s);printf("The result is:%sn",t);)fun(s,t);三、程序编写题#include<stdio.h>void fun(int a,int b,long*c)main()/*主函数*/int a,b;long c;void NONO();printf("Input a b:");scanf("%d%d",&a,&b);fu
4、n(a,b,&c);printf("The result is:%ldn",c);NONO();)void NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;int i,a,b;long c;rf=fopen("K:k0124010001in.dat","r");wf=fopen("K:kO 1W24010001 out.dat","w");for(i=0;i<10;i+)fscanf(rf,"%d,%d",
5、&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ldn",a,b,c);)fclose(rf);fclose(wf);)第 22套题一、程序填空题#include<stdio.h>int fun(int x)int n,si,s2,s3,t;n=0;t=100;/*found*/while(t<=1 )/*found*/sl=t%l 0;s2=(_2_)%10;s3=t/100;/*found*/if(s 1+S2+S3=_ 3_)printf("%d",t);n+;)t+
6、;)return n;)main()int x=-l;while(x<0)printf("Please input(x>0):");scanf("%d",&x);printf("nThe result is:%dn",fun(x);二、程序改错题#include⁢stdio.h>/*字字*不found*/void fun(long s,long t)long sl=10;s/=10;*t=s%10;/*亭*字 found*亭*/while(s<0)s=s/100;*t=s%10*sl+*t;si=
7、si*10;)main()long s,t;printf("nPlease enter s:");scanf("%ld",&s);fun(s,&t);printf("The result is:%ldn",t);)三、程序编写题#include<stdio.h>#define N 16typedef struct char num10;int s;STREC;void fun(STREC a)main()STRECsN="GA005",85,"GA003",76,&q
8、uot;GA002",69,"GA004",85,"GA001",91,"GA007",72,"G A008",64,"GA006",87),"GA015",85,"GA013",91,"GA012",64,"GA014",91,"GA011",66,"GA017",64,"GA018",64,"GA016",72;int i;
9、FILE*out;fun(s);printf("The data after sorted:n");for(i=0;i<N;i+)if(i)%4=0)printf("n");printf("%s%4d",si.num,si.s);)printf("n");out=fopen("K:kO 1W24010001 out.dat","w");for(i=0;i<N;i+)if(i)%4=0&&i)fprintf(out,"n");fp
10、rintf(out,"%4d",si.s);)fprintf(out,"n");fclose(out);)第 23套题一、程序填空题#include<stdio.h>unsigned long fun(unsigned long n)unsigned long x=0,s,i;int t;s=n;/*fou nd*不/i=_ 1 _;/*fou nd*/while(2)t=s%10;if(t%2=0)/*字 不*fou nd*/x=x+t*i;i=_ 3 _;)s=s/10;return x;main()unsigned long n=-l;
11、while(n>99999999lln<0)printf("Pleasescanf("%ld",&n);)input(O<n<100000000):");printf("nThe result is:%ldn",fun(n);二、程序改错题#include<stdio.h>#define M 5/*und*/int fun(int n,int xx)int i,j,sum=0;printf("nThe%d x%d matrix:n",M,M);for(i=0;i<M
12、;i+)for(j=0;j<M;j+)/*字 *f)und*不萃*/printf("%f",xxij);printf("n");)for(i=0;i<n;i+)sum+=xxii+xxif n-i-1;return(sum);main()int aaMM=1,2,3A5,4,3,2,1,0,678,9,0,9,8,7,6,5,3,4,5,6,7;printf("nThe sum of all elements on 2 diagnals is%d.",fun(M,aa);三、程序编写题#include<stdio.h
13、>void fun(int a,int b,long*c)(main()int a,b;long c;void NONO();printf("Input a b:");scanf("%d%d",&a,&b);fun(a,b,&c);printf("The result is:%ldn",c);NONO();)void NONO()/*本函数用于打开文件,输入数据-,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;int i,a,b;long c;rf=fopen("K:k0124010
14、001in.dat","r");wf=fopen("K:kO IW24010001 out.dat","w");for(i=0;i<10;i+)fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ldn",a,b,c);)fclose(rf);fclose(wf);第 24套题一、程序填空题#include<stdio.h>unsigned long fun(unsigne
15、d long n)unsigned long x=0;int t;while(n)t=n%10;/*found*/if(t%2=_l_)/*字 不 *sjjfou nd*字/x=_ 2 _+t;/*fou nd*不/n=_ 3 _;)return x;)main()unsigned long n=-l;while(n>99999999lln<0)printf("Please input(O<n<l 00000000):");scanf("%ld",&n);printf("nThe result is:%ldn&q
16、uot;,fun(n);)二、程序改错题#include<stdio.h>void fun(long s,long 九)int d;long sl=l;/*und*/t=0;while(s>0)d=s%10;/*found*/if(d%2=0)*t=d*si+*t;si*=10;)s/=10;)main()long s,t;printf("nPlease enter s:");scanf("%ld",&s);fun(s,&t);printf("The result is:%ldn",t);三、程序编写
17、题#include<stdio.h>void fun(char plf,char p2)()main()char si80,s240;void NONO();printf("Enter si and s2:n");scanf("%s%s",s 1,s2);printf("s 1 =%sn",s i);printf("s2=%sn",s2);printf("Invoke fun(s 1 ,s2):n");fun(sl,s2);printf("After invoking:n&
18、quot;);printf("%sn",s i);NONO();void NONO()/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/intFILE*rf,*wf;charsl8O,s240;rf=fopen("K:k0124010001in.dat","r");wf=fopen("K:kO 1W24010001 out.dat","w");for(i=0;i<10;i+)fscanf(rf,"%s"s i);fscanf(rf,"
19、;%s",s2);fun(sl,s2);fprintf(wf,"%sn",s i);)fclose(rf);fclose(wf);第 25套题一、程序填空题#include<stdio.h>void fun(unsigned long*n)unsigned long x=0,i;int t;i=l;while(*n)/*found*/t=*n%_ 1;/*found*/if(t%2!=_ 2 _)x=x+t*i;i=i*10;*n=*n/10;)/*found*/*n=3;)main()unsigned long n=-l;while(n>999
20、99999lln<0)printf("Please input(O<n<100000000):");scanf("%ld",&n);fun(&n);printf("nThe result is:%ldn",n);)二、程序改错题#include<stdio.h>double fun(int n)double result=1.0;/*found*/f n 0return 1.0;while(n>l&&n<170)/*/result n_return result
21、;)main()int n;printf("Input N:");scanf("%d",&n);printf("nn%d!=%lfnn",n,fun(n);三、程序编写题#include<stdio.h>#include<string.h>long fun(char*p)/*以下代码仅供参考*/int i,len,t;/*len 为串长,t 为正负标识*/long x=0;len=strlen(p);if(p0=u)t=-l;len-;p+;else t=l;/*以下完成数字字符串转换为个数字*/ret
22、urn x*t;)main()/*主函数*/chars6;void NONO();long n;printf("Enter a string:n");gets(s);n=fun(s);printf("%ldn",n);NONO();)void NONO()/*本函数用于打开文件,输入数据:调用函数,输出数据,关闭文件。FILE*fp,*wf;in ti;char s20J;long n;fp=fopen("K:kO 1W24010001 in.dat","r");wf=fopen("K:kO 1W2401
23、0001 out.dat","w");for(i=0;i<10;i+)fscanf(fp,"%s",s);n=fun(s);fprintf(wf,"%ldn",n);fclose(fp);fclose(wf);)第 26套题、程序填空题*/#include<stdio.h>double fun(int n)int i;double s,t;for(i=l;i<=2;i+)t=2.0*i;/*found*/s=s+(2.0*i-l)*(2.0*i+1)/_3_;)return s;)main()int
24、n=-l;while(n<O)printf("Please input(n>O):");scanf("%d",&n);printf("nThe result is:%fn",fun(n);)二、程序改错题#include<stdio.h>int fun(char*str,char*substr)int i,j,k,num=0;/*found*/for(i=0,stri,i+)for(j=i,k=0;substrk=strj;k+,j+)/*found*/If(substrk+l=t0,)num+;bre
25、ak;)return num;)main()char str80,substr80;printf("Input a string:");gets(str);printf("Input a substring:");gets(substr);printf("%dn",fun(str,substr);)三、程序编写题#include<stdio.h>#include<math.h>double fun(double eps)()main()double x;void NONO();printf("Inpu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 二级 语言 题库
限制150内