1、版全国计算机等级考试二级C教程课后编程题答案 2013版全国计算机等级考试二级C教程课后编程题答案3-16#includemain()double a,b,c,s,v;printf(input a,b,c:);scanf(a=%f b=%f c=%f, &a,&b,&c);s=a*b;v=a*b*c;printf(a=%f,b=%f,c=%fn,a,b,c);printf(s=%f,v=%f,s,v);return 0;3-17#include main()int a,b,c;printf(请输入需要划算成小时和分钟的数值n);scanf(%d,&a);b=a/60;c=a%60;printf
2、(a=%d小时%d分钟,b,c);return 0;3-18 #include main()int a,b,c,d;printf(请输入两个整数a和bn);scanf(%d %d,&a,&b);c=a/b;d=a%b;printf(a和b的商和余数分别是%d %d,c,d);return 0; 3-19#includemain()double a,b,c,d;printf(please input three numbersn);scanf(%lf%lf%lf,&a,&b,&c);d=(a+b+c)/3;printf(d=%lf,d);return 0;3-20#includemain()pr
3、intf(please input three numbers);int a,b,c,t;scanf(%d%d%d,&a,&b,&c);t=c;c=b;b=a;a=t;printf(a=%d,b=%d,c=%d,a,b,c);return 0;4-21#includemain()int a;printf(请输入a的值a=n);scanf(%d,&a);switch(a/10)case 0: printf(m=1); break;case 1: printf(m=1); break;case 2: printf(m=1); break;case 3: printf(m=2);break;case
4、 4: printf(m=3);break;case 5: printf(m=4);break;default: printf(m=5);return 0;4-22#includemain()int a,b,c,d,e,f,y,m,t;printf(please input her or his birthday n);scanf(%d%d%d,&a,&b,&c);printf(请输入现在的日期n);scanf(%d%d%d,&d,&e,&f);y=d-a;m=e-b;t=f-c;printf(该生的实际年龄是%d年%d月%d天,y,m,t);return 0;4-24#includemain
5、()int a,b,c,max;printf(请输入三个整数n);scanf(%d%d%d,&a,&b,&c);max=a;if(ab) max=b;if(maxc) max=c;printf(max=%d,max);return 0;4-25#include main()double x,y;printf(请输入x的值n);scanf(%lf,&x);if(-5x&x0) y=x;if(x=0) y=x-1;if(0x&x10) y=x+1;if(x10|x=10) printf(您输入的x的值不在查找范围内);printf(y=%lf,y);return 0;5-17#includemai
6、n()int n,i=1,t,sum=0;for(n=1;n=101;n+=2)t=i*n;sum+=t;i=-i;printf(sum=%d,sum);return 0;5-18#includemain()int t=1,n;float sum=1.0;for(n=1;n=50;n+)t=t*n;sum+=1/t;printf(e=%.3f,sum);return 0;5-19#includemain()int y,n=0;for(y=2000;y=3000;y+)if(y%4=0&y%100!=0|y%400=0)printf(%d ,y);n+;if(n%10=0) printf(n);
7、printf(n=%d,n);return 0;5-20#includemain()int i,j,k,m,n,h;for(i=1;i=3;i+)for(j=i;j=3;j+) printf( ); for(k=0;k2*i-1;k+) printf(*); printf(n);for(m=0;m4;m+)for(n=0;nm;n+) printf( ); for(h=0;h7-2*m;h+) printf(*);printf(n);return 0;6-19#includemain()char ch;int n=0;printf(请输入一行字符并用回车换行符结束输入n);doch=getch
8、ar();printf(ch=%c ASCII=%d ,ch,ch);n+;if(n%3=0) putchar(n);while(ch=getchar()!=n);putchar(n);return 0;6-20#includemain()char ch;printf(请输入一行字符并用回车换行符结束输入n);while(ch=getchar()!=n)if(ch!= ) printf(%c,ch);putchar(n);return 0;6-216-21#includemain()printf(请输入几行数字并用!来结束n);char ch;int n=0;while(ch=getchar(
9、)!=!)if(ch=n) n+;printf(输入的行数是:);printf(%d,n);return 0;6-22#includemain()char ch;int n=0;printf(请输入一行字符并用回车换行符结束输入n);while(ch=getchar()!=n) if(ach&chz) n+;printf(n=%d,n);putchar(n);return 0;6-23#includemain() int i,j,k;for(i=1;i=5;i+)for(j=0;j=5-i;j+) printf( );for(k=0;k2*i-1;k+) printf(%c,A+i-1);pu
10、tchar(n);return 0;int mymod(int a,int b)int c;c=b%a;return c;7-15#includemain() int a,b,c;printf(please input two numbersn);scanf(%d%d,&a,&b);c=mymod(a,b);printf(所求余数是%d,c);return 0;7-16#includemain()int m,n;printf(请输入m的值n);scanf(%d,m);double t=1.0;for(n=2;n=m;n+)t+=1/(n*n);printf(t=%f,t);return 0;7
11、-17#includemain()int m,n;printf(请输入m的值n);scanf(%d,m);double t=1.0;for(n=2;n=m;n+)t+=1/(n*n);printf(t=%f,t);return 0;7-18float f(float x)float s;s=x*x-5*x+4;return s;#includemain()float t,y1;printf(请输入参数t的值n);scanf(%f,&t);y1=f(t);printf(y1=%f,y1);return 0;8-17void f( float a, float b, float *p1,float
12、 *p2)*p1=a+b;*p2=a-b;#includemain()float x, y ;printf(请输入x和y的值n);scanf (%f%f,x,y); f(x,y,&x,&y);printf(%f%f,x,y);return 0;8-18void f(int x ,int y ,int z ,int *p1 ,int *p2)*p1=x;*p2=z;if(*p1y) *p1=y;if(*p1z) *p1=z;if(*p2y) *p2=y;if(*p2x) *p2=x;#includemain()printf(请输入a b c的值n);int a,b,c;scanf(%d%d%d,
13、&a,&b,&c);f(a,b,c,&a,&b);printf(三个数中最小的数是%d最大的数是%d,a,b);return 0;9-27#includemain()char ch;int num9=0,i;printf(请输入一行字符以回车来结束输入n);while(ch=getchar()!=n) if(0ch&ch9) numch-0+=1;for(i=0;i9;i+)printf(%d字符出现的次数是:%d次n,i,numi);return 0;9-28#includemain()int a10=0,1,2,3,4,5,6,7,8,9,i,n;printf(请输入需要向前移动的第一个元
14、素的下标n(n0):n);scanf(%d,&n);for(i=n;i=9;i+) ai-1=ai;for(i=0;i=8;i+)printf(%d ,ai);return 0;9-29#include#includemain()int y20,h20,k=0,i,j;printf(y数组中的值如下n);for(i=0;i20;i+) yi=rand()%99;printf(%d ,yi);for(i=0;i=10;i+)if(yi%2=1) hk=yi;k+;printf(y数组中的奇数如下n);for(j=0;jk;j+)printf(%d ,hj);return 0;9-30#inclu
15、demain()int j,p,k,m;char a8=a,2,c,d,e,f,g,9,t;for(j=0;j8;j+)if(A=aj&aj=z) p=j;for(k=j+1;k7;k+)if(A=ak&ak=z)if(apak) p=k;t=aj; aj=ap; ap=t;for(m=0;m=7;m+)printf(%c ,am);return 0;9-31#includemain()int i=0,m;char ch,a11=0,x;printf(请输入8个有序的数n);do ch=getchar();ai=ch;i+;while(ch=getchar()!=n);printf(输入的数分
16、别是:);for(m=0;m8;m+)printf( a%d=%cn ,m,am);putchar(n);printf(请输入需要插入的数n);int j,k,s,l,p;scanf(%c,&x);if(x=1;l-)al=al-1;a0=x;if(a0x&xa9)for(j=0;j=8;j+)if(ajx&xj+1;k-)ak=ak-1;ap=x;if(xa9) a10=x;for(s=0;s=8;s+)printf(%c ,as);return 0;9-32#includemain()int h,j,i,k,a15;printf(请输入需要转化成2进制的10进制数n);scanf(%d,&
17、h);doj=h%2;h=h/2;ai=j;i+;while(h/2=0);for(k=i;k=0;k-)printf(%d,ak);return 0;9-33#include#includemain()int i=0,n=1,a15,j,x;x=rand()%20;ai=x;for(j=0;n=14;j+) x=rand()%20;while(in&x!=ai) i+; if(i=n) an=x; n+; i=0;printf(a数组中不重复的15个数是:);for(j=0;j=14;j+)printf(%d ,aj);return 0;9-34#include #include main(
18、)int a55,k=0,c1=0,c2=0,h5=0,e5=0,o,i,j,l,n,y,z;for(i=0;i5;i+)for(j=0;j5;j+)aij=rand()%30;printf(%d ,aij);k+;if(k%5=0)printf(n);for(z=0;z=4;z+)c1=c1+azz;c2=c2+az5-z;printf(c1=%d c2=%dn,c1,c2);for(l=0;l5;l+)for(n=0;n5;n+)hl=hl+aln;el=el+anl;for(o=0;o5;o+)printf(h%d=%d ,o,ho);printf(n);for(y=0;y=4;y+)p
19、rintf(e%d=%d ,y,ey);return 0;9-36includemain()int a99,k,i,j;printf( * * A MULTIPLICATION TABLE * *n);printf(.n);printf( (1);for(k=2;k=9;k+)printf( (%d),k);printf(n);for(i=0;i9;i+)printf(%d) ,i+1);for(j=0;j9;j+)aij=(i+1)*(j+1);printf(%-4d ,aij);printf(n);printf(.n);return 0;9-37#include#includemain()
20、int a55,i,j,k,m;for(i=0;i5;i+)for(j=0;j5;j+) aij=rand()%100; printf(%-4d,aij); printf(nn);printf(转置后的距阵如下n); for(k=0;k5;k+) for(m=0;m5;m+) printf(%-4d,amk); printf(n); return 0;10-19#includescomp(char*s1,char*s2)int i;i=0;while(sli=s2i&s1i) i+;jreturn (s1i-s2i);main()char str1=ABC,str210;get(tr2);if
21、(scomp(str1,str2)str2n);else if(scomp (str1,str2)0) printf(str1str2n); else printf(str1=str2n);10-20#includevoid gettext (char(*)61,int*);void puttext (char61,int);main()char text4061;int n;gettext (text,&n);puttext (text,n);void gettext (char(*t)61,int*m) int n;printf(enter texline,ended to empty l
22、ine:n);n=0;gets(tn);while(*tn)n+;gets(tn);*m=n;void puttext (char t61,int n) int i;for(i=0;in;i+) printf(%-2d:,i+1);puts(ti);10-21#include#includegetstr(char p80)char t80;int n=0;printf(enter string.a empty sring to endn);gets(t);while(strcmp(t, )strcmp(pn,t);n+;return n;char*findmin(char(*a)80,int
23、n)char*p;int i;p=a0;for(i=0;i=n;i+)if(strcmp(p,ai) p=ai;return p;11-11#include#includemain(int argv,char*a)char str=Ilove you pretty because not olny are you elegent but also you make so success;int i;printf(请输入outch或 outch -2 或outch +6n);if(*(a1+1)=2)for(i=0;i=1;i+)printf(%c,strstrlen(str)-1-i);if(*(a1+1)=6)for(i=0;i=5;i+)printf(%c,stri);if(argv=1)for(i=0;i=10;i+)printf(%c,stri);return 0;11-12#includevoid f(int n)int d,t;d=n%2;printf(%d,d);t=n/2;if(t=1) f(t);main()int num;printf(请输入一个10进制的数n);scanf(%d,&num);f(num);return 0;11-13#includeint f(int n)int t=0;if(n!=0) return n+
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1