欢迎来到天天文库
浏览记录
ID:53123351
大小:16.63 KB
页数:11页
时间:2020-04-01
《C++经典编程练习题.docx》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C++经典编程例题(1)1、(已验证!)计算铁路运费。已知从甲地到乙地,每张票托运行李不超过50公斤时,按每公斤0.13元,超过50公斤,超过部分按每公斤0.2元计算。输入行李重量w,计算运费y.#includeusingnamespacestd;voidmain(){floatmoney=0,weight;cout<<"请输入货物重量(单位:千克):";cin>>weight;if(weight<0)cout<<”数据错误!”<2、eight*0.13;elseif(weight>50)money=50*0.13+(weight-50)*0.2;cout<<"总费用是:"<#includeusingnamespacestd;voidmain(){ doublea,b,c,p,x1,x2,D; cout<<"请输入3个数:"<3、; cout<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"c="; cin>>c; cout<<"方程为:"<4、endl; cout<<"x1=x2="<0) { p=-b/(2*a); x1=p+sqrt(D)/(2*a); x2=p-sqrt(D)/(2*a); cout<<"方程有两个不同的实根。"<5、eam>usingnamespacestd;voidmain(){ inti,n,s; s=1; cout<<"inputn:"; cin>>n; for(i=1;i<=n;i++) s=i*s; cout<usingnamespacestd;voidmain(){ inti,n,s; s=1; i=1; cout<<"inputn:"; cin>>n; while(i<=n) 6、{ s=i*s; ++i; } cout<usingnamespacestd;voidmain(){ constintcoc7、k=20,hen=33,chicken=100; intc,h,ck; for(c=0;c<=cock;c++){ for(h=0;h<=hen;h++){ for(ck=0;ck<=chicken;ck++){ if(((c+h+ck)==100)&&((c*5+h*3+ck/3)==100)&&((ck%3)==0)) cout<<"鸡翁,鸡婆,鸡雏各:"<8、"<usingnamespacestd;voidmain(){ intc,h,ck; for(h=0;h<33;h++) for(ck=0;ck<100;ck++){ c
2、eight*0.13;elseif(weight>50)money=50*0.13+(weight-50)*0.2;cout<<"总费用是:"<#includeusingnamespacestd;voidmain(){ doublea,b,c,p,x1,x2,D; cout<<"请输入3个数:"<3、; cout<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"c="; cin>>c; cout<<"方程为:"<4、endl; cout<<"x1=x2="<0) { p=-b/(2*a); x1=p+sqrt(D)/(2*a); x2=p-sqrt(D)/(2*a); cout<<"方程有两个不同的实根。"<5、eam>usingnamespacestd;voidmain(){ inti,n,s; s=1; cout<<"inputn:"; cin>>n; for(i=1;i<=n;i++) s=i*s; cout<usingnamespacestd;voidmain(){ inti,n,s; s=1; i=1; cout<<"inputn:"; cin>>n; while(i<=n) 6、{ s=i*s; ++i; } cout<usingnamespacestd;voidmain(){ constintcoc7、k=20,hen=33,chicken=100; intc,h,ck; for(c=0;c<=cock;c++){ for(h=0;h<=hen;h++){ for(ck=0;ck<=chicken;ck++){ if(((c+h+ck)==100)&&((c*5+h*3+ck/3)==100)&&((ck%3)==0)) cout<<"鸡翁,鸡婆,鸡雏各:"<8、"<usingnamespacestd;voidmain(){ intc,h,ck; for(h=0;h<33;h++) for(ck=0;ck<100;ck++){ c
3、; cout<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"c="; cin>>c; cout<<"方程为:"<4、endl; cout<<"x1=x2="<0) { p=-b/(2*a); x1=p+sqrt(D)/(2*a); x2=p-sqrt(D)/(2*a); cout<<"方程有两个不同的实根。"<5、eam>usingnamespacestd;voidmain(){ inti,n,s; s=1; cout<<"inputn:"; cin>>n; for(i=1;i<=n;i++) s=i*s; cout<usingnamespacestd;voidmain(){ inti,n,s; s=1; i=1; cout<<"inputn:"; cin>>n; while(i<=n) 6、{ s=i*s; ++i; } cout<usingnamespacestd;voidmain(){ constintcoc7、k=20,hen=33,chicken=100; intc,h,ck; for(c=0;c<=cock;c++){ for(h=0;h<=hen;h++){ for(ck=0;ck<=chicken;ck++){ if(((c+h+ck)==100)&&((c*5+h*3+ck/3)==100)&&((ck%3)==0)) cout<<"鸡翁,鸡婆,鸡雏各:"<8、"<usingnamespacestd;voidmain(){ intc,h,ck; for(h=0;h<33;h++) for(ck=0;ck<100;ck++){ c
4、endl; cout<<"x1=x2="<0) { p=-b/(2*a); x1=p+sqrt(D)/(2*a); x2=p-sqrt(D)/(2*a); cout<<"方程有两个不同的实根。"<5、eam>usingnamespacestd;voidmain(){ inti,n,s; s=1; cout<<"inputn:"; cin>>n; for(i=1;i<=n;i++) s=i*s; cout<usingnamespacestd;voidmain(){ inti,n,s; s=1; i=1; cout<<"inputn:"; cin>>n; while(i<=n) 6、{ s=i*s; ++i; } cout<usingnamespacestd;voidmain(){ constintcoc7、k=20,hen=33,chicken=100; intc,h,ck; for(c=0;c<=cock;c++){ for(h=0;h<=hen;h++){ for(ck=0;ck<=chicken;ck++){ if(((c+h+ck)==100)&&((c*5+h*3+ck/3)==100)&&((ck%3)==0)) cout<<"鸡翁,鸡婆,鸡雏各:"<8、"<usingnamespacestd;voidmain(){ intc,h,ck; for(h=0;h<33;h++) for(ck=0;ck<100;ck++){ c
5、eam>usingnamespacestd;voidmain(){ inti,n,s; s=1; cout<<"inputn:"; cin>>n; for(i=1;i<=n;i++) s=i*s; cout<usingnamespacestd;voidmain(){ inti,n,s; s=1; i=1; cout<<"inputn:"; cin>>n; while(i<=n)
6、{ s=i*s; ++i; } cout<usingnamespacestd;voidmain(){ constintcoc
7、k=20,hen=33,chicken=100; intc,h,ck; for(c=0;c<=cock;c++){ for(h=0;h<=hen;h++){ for(ck=0;ck<=chicken;ck++){ if(((c+h+ck)==100)&&((c*5+h*3+ck/3)==100)&&((ck%3)==0)) cout<<"鸡翁,鸡婆,鸡雏各:"<8、"<usingnamespacestd;voidmain(){ intc,h,ck; for(h=0;h<33;h++) for(ck=0;ck<100;ck++){ c
8、"<usingnamespacestd;voidmain(){ intc,h,ck; for(h=0;h<33;h++) for(ck=0;ck<100;ck++){ c
此文档下载收益归作者所有