《C语言程序设计》阅读程序写结果试题汇总7948.pdf
《《C语言程序设计》阅读程序写结果试题汇总7948.pdf》由会员分享,可在线阅读,更多相关《《C语言程序设计》阅读程序写结果试题汇总7948.pdf(71页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、记号:蓝色表示已做并且没有问题的 红色表示已做但不是很顺手,需注意的 黄色表示不会做 黑色表示未做 第四章:17 阅读程序写结果试题 第四章 选择结构 (共 20 道题)1.(于蕾)#include void main()int x,y,t;x=7;y=9;if(xy)t=x;x=y;y=t;printf(%d,%dn,x,y);运行结果:9,7 2.(于蕾)#include void main()int x=1,a=2,b=3;switch(x)case 1:a-;break;case 2:b+;break;case 3:a+;b+;printf(na=%d,b=%dn,a,b);运行结果:
2、a=1,b=3 3.(于蕾)#include void main()char ch1=E;if(ch1=A)ch1+;else ch1+=32;printf(ch1=%cn,ch1);运行结果:ch1=F 4.(于蕾)#include void main()int x,y,t;x=5;y=3;if(xy)t=x;x=y;y=t;printf(%d,%dn,x,y);运行结果:3,5 5.(王伟)#include int main()int a,b,c,m;printf(Enter three integers:);scanf(%d%d%d,&a,&b,&c);if(a=b)m=a;else m
3、=b;if(cm)m=c;printf(m=%dn,m);return 0;输入:21 22 23 运行结果:m=21 6.(王伟)#include int main()char ch1=a,ch2=B,ch3=E;if(ch1ch2)if(ch2ch3)ch3+;else -ch3;printf(ch3=%cn,ch3);return 0;运行结果:ch3=D 7.(王伟)#include int main()float x,y;scanf(%f,&x);switch(int)x/10)case 0:y=;printf(y=%fn,y);break;case 1:y=2*x+1;printf
4、(y=%fn,y);break;case 2:y=3*x*x+2;printf(y=%fn,y);break;default:printf(No definition.n);return 0;输入:运行结果:y=8.(王伟)#include int main()char ch1=A,ch2=B;switch(ch1)!特别要注意每个分句的最末尾有无break!case A:switch(ch2)case B:printf(Good!n);break;case A:printf(Better!n);break;case B:printf(Best!n);break;return 0;运行结果:G
5、ood!Best!9(王锋)#include void main()float score;score=100;if(score60)printf(En);else switch(int)score/10)case 10:case 9:printf(An);case 8:printf(Bn);case 7:printf(Cn);break;case 6:printf(Dn);break;default:printf(Errorn);运行结果:A B C 10(王锋)#include void main()int i=0,a=2;if(i=0)printf(“*”);else printf(“$
6、”);printf(“*”);运行结果:*11.(王锋)#include void main()int m=10,n=0,p=4,q=20;if(m)if(n)q=15-m;else q=25+m;else if(p)q=q+p;printf(“q=%dn”,q);运行结果:q=35 12.(王锋)#include void main()int a=1,b=0;switch(a)case 1:switch(b)case 0:printf(“*0*”);break;case 1:printf(“*1*”);break;case 2:printf(“*2*”);break;运行结果:*0*2*13
7、.(宋昕)#include int main()int a=2,b=7,c=5;switch(a0)case 1:switch(b0)case 1:printf();break;case 2:printf(!);break;case 0:switch(c=5)case 1:printf(*);break;default:printf(#);break;default:printf(&);printf(n);return 0;运行结果:*&14.(宋昕)#include int main()int a=0,b=1,c=0,d=20;if(a)d=d-10;else if(!b)if(!c)d=1
8、5;else d=25;printf(d=%dn,d);return 0;运行结果:d=20 15.(宋昕)#include int main()int a=1;switch(a)case 0:printf(*0*);break;case 1:printf(*1*);break;case 2:printf(*2*);break;return 0;运行结果:*1*16.(宋昕)#include int main()int x,y;scanf(%d,&x);y=x12 x+10:x-12;printf(%dn,y);return 0;输入:12 运行结果:0 17.(宋昕)#include int
9、 main()float x,y;char op;double r;scanf(%c%f%f,&op,&x,&y);switch(op)case+:r=x+y;break;case-:r=x-y;break;case*:r=x*y;break;case/:r=x/y;break;printf(%.1f,r);return 0;输入:运行结果:18.(王勇超)#include void main()int a=7;if(a9|a10)a=a/3;else a=a%3;printf(a=%d,a);运行结果:a=2 19.(王勇超)#include void main()int a=20;swit
10、ch(a%3)case 0:printf(0);case 1:printf(1);case 2:printf(2);default:printf(3);printf(4);运行结果:234 20.(王勇超)#include void main()int a=2,b=5,c=8,t;if(a b)t=a;a=b;b=t;if(b c)t=b;b=c;c=t;if(a b)t=a;a=b;b=t;printf(%d,%dn,a+,-c);运行结果:8,1 第五章 循环结构 共 20 道题 1.(于蕾)#include void main()int number,digit;number=1234;
11、while(number!=0)digit=number%10;printf(%d,digit);number=number/10;运行结果:4321 2.(于蕾)#include#define N 5 void main()int i;for(i=1;iN;i+)printf(%dn,i*i);运行结果:1 4 9 16 3.(于蕾)#include void main()int i,s,x;s=0;x=15;for(i=1;i=5;i+)if(x%i=0)s=s+i;printf(i=%d,s=%dn,i,s);运行结果:i=6,s=9 4.(于蕾)#include void main()
12、int counter=1;while(counter=5)printf(%d n,counter);counter+;运行结果:1 2 3 4 5 5(王伟)#include int main()int i,sum,m,a;sum=0;m=5;for(i=0;im)sum+=a;printf(sum=%dn,sum);return 0;输入:2 10 8 3 运行结果:sum=18 6.(王伟)#include int main()int i,j,k;for(i=1;i=4;i+)for(j=1;j5-i;j+)printf();for(k=1;k=i;k+)printf(*);printf
13、(n);return 0;运行结果:*7.(王伟)#include int main()int i,j;i=1;while(i5)for(j=1;j2*i+1;j+)printf(%c,#);printf(n);i+;return 0;运行结果:#8.(王伟)#include int main()int i=10,m=0,n=0;do if(i%2!=0)m=m+i;else n=n+i;i-;while(i=0);printf(m=%d,n=%dn,m,n);return 0;运行结果:m=25,n=30 9(王锋)#include void main()int sum=0,n;scanf(
14、%d,&n);while(n=5)sum+=n;n+;printf(sum=%d,sum);输入:1 运行结果:sum=15 10(王锋)#include void main()int i,j;for(i=2;i=0;i-)for(j=1;j=i;j+)printf(*);for(j=0;j=2-i;j+)printf(!);printf(n);运行结果:*!*!11(王锋)#include void main()int a,b;for(a=1,b=1;a20)break;if(b%4=1)b=b+4;continue;b=b-5;printf(a=%dn,a);运行结果:a=6 12(王锋)
15、#include void main()char k;int i;for(i=1;i3;i+)scanf(%c,&k);switch(k)case 0:printf(anothern);case 1:printf(numbern);输入:01 运行结果:another number number 13.(宋昕)#include int main()int i,s=0;for(i=1;i 10)break;printf(i=%d,s=%dn,i,s);return 0;运行结果:i=3,s=14 14.(宋昕)#include void main()char ch;while(ch=getcha
16、r()!=n)if(ch=A&ch=a&ch=z)ch=ch-32;printf(%c,ch);输入:ABCdef 运行结果:abcDEF 15.(宋昕)#include int main()int a,b;for(a=1,b=1;a=9)break;if(b%3=1)b+=3;continue;b-=5;printf(%d,%dn,a,b);return 0;运行结果:4,10 16.(宋昕)#include int main()int i=0,j=0;while(i 10)i+;while(j+10);printf(i=%d,j=%dn,i,j);return 0;运行结果:i=10,j=
17、11 17.(王勇超)#include void main()int i,j,t;for(i=1,j=10;i 4);运行结果:010101 19(王勇超)#include void main()int i=7,j;while(i 2)j=i%2;printf(%d,j);i-;printf(%d,i);运行结果:101012 20.(王勇超)#include void main()int i,j,t=0;for(i=3;i0;i-)for(j=0;j4;j+)t+=j;printf(t=%d,t);运行结果:t=18 第六章 函数 共 40 道题 1.(王伟)#include long fu
18、n(int x,int n);int main()int x=3,n=3;long p;p=fun(x,n);printf(p=%ldn,p);return 0;long fun(int x,int n)int i;long p=1;for(i=0;in;i+)p*=x;return p;运行结果:p=27 2.(王伟)#include int isDigit(char ch);int main()char ch;while(ch=getchar()!=n)if(isDigit(ch)putchar(ch);printf(n);return 0;int isDigit(char ch)if(c
19、h=0&ch=9)return 1;else return 0;输入:Abc1d23eF45g 运行结果:12345 3.(王伟)#include void odddivisor(int n);int main()int n;scanf(%d,&n);odddivisor(n);return 0;void odddivisor(int n)int i;for(i=3;i=n/2;i=i+2)if(n%i=0)printf(%5d,i);printf(n);输入:15 运行结果:3 5 4.(王伟)#include void print();int a=5;int main()int a=1,b
20、=2;a=a+b;print();printf(%d%dn,a,b);return 0;void print()int b=3;printf(%d%dn,a,b);运行结果:5 3 3 2 5.(王伟)#include int fun1(int x);void fun2(int x);int main()int x=1;x=fun1(x);printf(%dn,x);return 0;int fun1(int x)x+;fun2(x);return x;void fun2(int x)x+;运行结果:2 6.(王伟)#include int fun1(int a,int b,int c);in
21、t main()int a=11,b=21,c=31;fun1(a,b,c);printf(%d%d%dn,a,b,c);return 0;int fun1(int a,int b,int c)a=a+10;b=b+10;c=c+10;return c;运行结果:11 21 31 7.(王伟)#include void fun(int x);int main()fun(7);printf(n);return 0;void fun(int x)if(x/21)fun(x/2);printf(%5d,x);运行结果:3 7 8.(王伟)#include void fun(int a);int ma
22、in()int i,a5=1,2,3;fun(a);for(i=0;i5;i+)printf(%5d,ai);printf(n);return 0;void fun(int a)int i;for(i=0;i5;i+)ai+=5;运行结果:6 7 8 5 5 9.(于蕾)#include void fun(int k);void main()int w=5;fun(w);printf(n);void fun(int k)if(k0)fun(k-1);printf(%d,k);运行结果:012345 10.(于蕾)#include void f1(void);int a=1;void main(
23、)int a=2;f1();int a=3;printf(a2=%dn,a);printf(a3=%dn,a);void f1(void)printf(a1=%dn,a);运行结果:a1=1 a2=3 a3=2 11.(于蕾)#include void f(int a,int b,int*c)a=20;b=10;*c=a+b;void main()int a=10,b=20,c=30,d=40;f(a,b,&c);printf(%d,%d,%dn,a,b,c);运行结果:10,20,30 12.(于蕾)#include void swap(int a,int b);void main()int
24、 a=2,b=3;printf(a=%d,b=%dn,a,b);swap(a,b);printf(a=%d,b=%dn,a,b);void swap(int a,int b)int c;c=a;a=b;b=c;运行结果:a=2,b=3 a=2,b=3 13.(于蕾)#include void fun(int a,int b,int c);void main()int x=10,y=20,z=30;fun(x,y,z);printf(%d,%d,%dn,x,y,z);void fun(int a,int b,int c)a=456;b=567;c=678;运行结果:10,20,30 14.(于蕾
25、)#include float f(int n)int i;float s=;for(i=1;in;i+)s=s+(float)i;return s;void main()int i;float a=;for(i=1;i3;i+)a=a+f(i);printf(a=%.4fn,a);运行结果:a=15.(于蕾)#include int f(int a);void main()int a=2,i;for(i=0;i3;i+)printf(%d,f(i);int f(int a)int b=0,c=3;b+;c+;return(a+b+c);运行结果:567 16.(于蕾)#include int
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言程序设计 语言程序设计 阅读 程序 结果 试题 汇总 7948
限制150内