资源描述:
《北理工网络教室c语言编程练习》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、北理工网络教室C语言编程练习输入x的值,求对应的y的值。#includeintmain(){intx,y;scanf("%d",&x);if(x>2&&x<=10)printf("%d",x*(x+2));elseif(x>-1&&x<=2)printf("%d",2*x);elseif(x<=-1)printf("%d",x-1);elseprintf("Error");}将四个整数按顺序输出#includeintmain(){inta,b,c,d;scanf("%d,%d,%d,%d",&a,&b,&c,&d);if(a>b){a+
2、=b;b=a-b;a-=b;}if(a>c){a+=c;c=a-c;a-=c;}if(a>d){a+=d;d=a-d;a-=d;}if(b>c){b+=c;c=b-c;b-=c;}if(b>d){b+=d;d=b-d;b-=d;}if(c>d){c+=d;d=c-d;c-=d;}printf("%d,%d,%d,%d",a,b,c,d);}花多少钱买衣服#includeintmain(){inta,b,m;scanf("a=%d,b=%d",&a,&b);if(a>=b&&b>=50)m=80*b+60*(a-b);if(a>=b&&b<50)m=90*b+60*(
3、a-b);if(b>=a&&a>=50)m=80*a+45*(b-a);if(b>=a&&a<50)m=90*a+45*(b-a);printf("m=%d",m);}到邮局去寄包裹#includeintmain(){floata,b,c,m,s;scanf("%f,%f,%f,%f",&a,&b,&c,&m);if(a>1
4、
5、b>1
6、
7、c>1
8、
9、m>30)printf("Error");else{if(m<=10)s=0.8*m+0.2;if(m>10&&m<=20)s=0.75*m+0.2;if(m>20&&m<=30)s=0.7*m+0.2;printf(
10、"%.2f",s);}}自学循环---判断谁是案犯#includeintmain(){inta,b,c,d,e,f;for(a=0;a<2;a++)for(b=0;b<2;b++)for(c=0;c<2;c++)for(d=0;d<2;d++)for(e=0;e<2;e++)for(f=0;f<2;f++)if(a+b>=1&&a+e+f>=2&&(!a
11、
12、!d)&&(b+c==2
13、
14、b+c==0)&&c+d==1&&(d
15、
16、!e))printf("%d,%d,%d,%d,%d,%d",a,b,c,d,e,f);}自学循环--看看是谁做的好事#include
17、tdio.h>intmain(){charT;for(T='A';T<='D';T++){if((T!='A')+(T=='C')+(T=='D')+(T!='D')==3)printf("%c",T);}}求一个整数的反序数#includeintmain(){intn;scanf("%d",&n);while(n){printf("%d",n%10);n/=10;}printf("");}编程,输出满足下列算式的各字母所代表的数字。PEAR-ARA───────PEA#includeintmain(){intP,E,A,R;for(P=1;P
18、<=9;P++)for(E=0;E<=9;E++)for(A=1;A<=9;A++)for(R=0;R<=9;R++){if(1000*P+100*E+10*A+R-(100*A+10*R+A)==100*P+10*E+A)printf("Theresultis:%d",1000*P+100*E+10*A+R);}}输出乘法九九表#includeintmain(){inti,j;for(i=1;i<=9;i++){for(j=1;j19、买水果用40元买苹果、西瓜和梨共100个,3种水果都要。已知苹果0.4元一个,西瓜4元一个,梨0.2元一个。问可以各买多少个?编程,输出全部购买方案#includeintmain(){inta,b,c;for(a=1;a<100;a++)for(b=1;b<10;b++){c=100-a-b;if(0.4*a+4*b+0.2*c==40)printf("%d,%d,%d",a,b,c);}}编程求一个三位数,其