资源描述:
《基本阅读程序题及答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、北京石油化工学院12级复习题基本输入输出7.#includemain(){inta=1,b=2;a=a+b;b=a-b;a=a-b;printf(“a=%d,b=%d”,a,b);}运行结果为:a=2,b=113.#includemain(){inta=3,b=4;intz=a+b;printf(“z=%d”,z);}运行结果为:z=717.#includemain(){intx,b0,b1,b2;printf("Pleaseenteranintegerx:");scanf("%d",&x);b2=x/10
2、0;b1=(x-b2*100)/10;b0=x%10;printf("bit0=%d,bit1=%d,bit2=%d",b0,b1,b2);}若输入352,运行结果为:bit0=2,bit1=5,bit2=3程序控制结构(顺序,分支,循环)1.#includemain(){inta=1,b=3,c=5;if(c==a+b)printf("yes");elseprintf("no");}运行结果为:no2.#includemain(){inta=12,b=-34,c=56,min=0;min=a;if(min>b)min=
3、b;if(min>c)min=c;printf("min=%d",min);}运行结果为:min=-343.#includemain(){intx=2,y=-1,z=5;if(xmain(){inta=10,b=50,c=30;if(a>b)a=b;b=c;c=a;printf("a=%db=%dc=%d",a,b,c);}运行结果为:a=10b=30c=105.#includemain(){f
4、loata,b,c,t;a=3;b=7;c=1;if(a>b){t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}printf("%5.2f,%5.2f,%5.2f",a,b,c);}运行结果为:1.00,2.00,7.006.#includemain(){inta=2;floatnum=3.12,x;if(num<4)x=2*num*a;printf("resultis%f",x);}运行结果为:"resultis12.48007.#includemain(){cha
5、rc=’A’;if((‘0’<=c)&&(c<=’9’))printf(“YES”);elseprintf(“NO”);}运行结果为:NO8.#includemain(){floatc=3.0,d=4.0;if(c>d)c=5.0;elseif(c==d)c=6.0;elsec=7.0;printf(“%.1f”,c);}运行结果为:7.09.#includemain(){inta=0,b=1,c=0,d=20;if(a)d=d-10;elseif(!b)if(!c)d=15;elsed=25;printf("d=%d",d
6、);}运行结果为:d=2010.#includemain(){inta=2,b=3,c=1;if(a>b)if(a>c)printf(“%d”,a);elseprintf(“%d”,c);printf(“over!”);}运行结果为:over!11.#includemain(){intm;scanf("%d",&m);if(m>=0){if(m%2==0)printf("%disapositiveeven",m);elseprintf("%disapositiveodd",m);}else{if(m%2==0)p
7、rintf("%disanegativeeven",m);elseprintf("%disanegativeodd",m);}}若键入-9,则运行结果为:-9isanegativeodd13.#includemain(){intx,y,z;x=20,y=40,z=60;while(xmain(){intnum=0;while(num<=2){num++;printf("