欢迎来到天天文库
浏览记录
ID:49226017
大小:95.50 KB
页数:28页
时间:2020-02-02
《程序设计 综合例题分析.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、例1:输入一实数,输出该实数,且保留小数后一位。(从样例可以看出:输入整数也要保留一位小数)setprecision(n):设置浮点数最大小数位数,若要输满小数位数,调用setiosflags(ios::fiexed),n包括小数点,若调用了setiosflags,则不包括小数点。#include#includevoidmain(){floatx;cin>>x;cout<2、例2:输入两个整数x、y,输出3、x-y4、。//程序一:#includevoidmain(){intx,y;cin>>x>>y;cout<<((x>y)?x-y:y-x);//必须外加括号,否则编译器解释为:(cout<<(x>y))?x-y:y-x;}#includevoidmain(){intx,y,k;cin>>x>>y;if(x>y)k=x-y;elsek=y-x;cout<5、题目表示造成)#includevoidmain(){intn,s=0,sign=1,i;cin>>n;for(i=1;i<=n;i=i+2){s+=i*sign;sign=sign*-1;}cout<voidmain(){intn,s=0,sign=1,i;cin>>n;for(i=1;i<=n;i++){s+=(2*i-1)*sign;sign=sign*(-1);}cout<6、ostream.h>inta(intn,ints)//无法解决正负交替的表示,使用参数{return(2*n-1)*s;}voidmain(){inti,n,s=0,sign=-1;cin>>n;for(i=1;i<=n;i++){s+=a(i,sign);sign=sign*-1;}cout<inta(intn){return(2*n-1)*(n%2==0?-1:1);}voidmain(){inti,n,s=0;cin>>n;for(i7、=1;i<=n;i++){s+=a(i);}cout<voidmain(){inti,n,a;cin>>n;a=1;cout<inta(intn){if(n==1)return1;returna(n-1)+n;}voidmain(){in8、ti,n;cin>>n;for(i=1;i<=n;i++){cout<voidexch(float&x,float&y){floatz;z=x;x=y;y=z;}voidmain(){floatheight1,height2,height3;cin>>height1>>height2>>height3;if(height2>he9、ight1)exch(height1,height2);//第二个数比第一个小if(height3>height2)exch(height2,height3);//最后一个最小if(height2>height1)exch(height1,height2);cout<10、#includevoidmain(){charc;cin>>c;switch(c){case'a':case'A':cout<<"Adition";break;case's':case'S':cout<<"Subtraction";break;default:cout<<"error";}cout<
2、例2:输入两个整数x、y,输出
3、x-y
4、。//程序一:#includevoidmain(){intx,y;cin>>x>>y;cout<<((x>y)?x-y:y-x);//必须外加括号,否则编译器解释为:(cout<<(x>y))?x-y:y-x;}#includevoidmain(){intx,y,k;cin>>x>>y;if(x>y)k=x-y;elsek=y-x;cout<5、题目表示造成)#includevoidmain(){intn,s=0,sign=1,i;cin>>n;for(i=1;i<=n;i=i+2){s+=i*sign;sign=sign*-1;}cout<voidmain(){intn,s=0,sign=1,i;cin>>n;for(i=1;i<=n;i++){s+=(2*i-1)*sign;sign=sign*(-1);}cout<6、ostream.h>inta(intn,ints)//无法解决正负交替的表示,使用参数{return(2*n-1)*s;}voidmain(){inti,n,s=0,sign=-1;cin>>n;for(i=1;i<=n;i++){s+=a(i,sign);sign=sign*-1;}cout<inta(intn){return(2*n-1)*(n%2==0?-1:1);}voidmain(){inti,n,s=0;cin>>n;for(i7、=1;i<=n;i++){s+=a(i);}cout<voidmain(){inti,n,a;cin>>n;a=1;cout<inta(intn){if(n==1)return1;returna(n-1)+n;}voidmain(){in8、ti,n;cin>>n;for(i=1;i<=n;i++){cout<voidexch(float&x,float&y){floatz;z=x;x=y;y=z;}voidmain(){floatheight1,height2,height3;cin>>height1>>height2>>height3;if(height2>he9、ight1)exch(height1,height2);//第二个数比第一个小if(height3>height2)exch(height2,height3);//最后一个最小if(height2>height1)exch(height1,height2);cout<10、#includevoidmain(){charc;cin>>c;switch(c){case'a':case'A':cout<<"Adition";break;case's':case'S':cout<<"Subtraction";break;default:cout<<"error";}cout<
5、题目表示造成)#includevoidmain(){intn,s=0,sign=1,i;cin>>n;for(i=1;i<=n;i=i+2){s+=i*sign;sign=sign*-1;}cout<voidmain(){intn,s=0,sign=1,i;cin>>n;for(i=1;i<=n;i++){s+=(2*i-1)*sign;sign=sign*(-1);}cout<6、ostream.h>inta(intn,ints)//无法解决正负交替的表示,使用参数{return(2*n-1)*s;}voidmain(){inti,n,s=0,sign=-1;cin>>n;for(i=1;i<=n;i++){s+=a(i,sign);sign=sign*-1;}cout<inta(intn){return(2*n-1)*(n%2==0?-1:1);}voidmain(){inti,n,s=0;cin>>n;for(i7、=1;i<=n;i++){s+=a(i);}cout<voidmain(){inti,n,a;cin>>n;a=1;cout<inta(intn){if(n==1)return1;returna(n-1)+n;}voidmain(){in8、ti,n;cin>>n;for(i=1;i<=n;i++){cout<voidexch(float&x,float&y){floatz;z=x;x=y;y=z;}voidmain(){floatheight1,height2,height3;cin>>height1>>height2>>height3;if(height2>he9、ight1)exch(height1,height2);//第二个数比第一个小if(height3>height2)exch(height2,height3);//最后一个最小if(height2>height1)exch(height1,height2);cout<10、#includevoidmain(){charc;cin>>c;switch(c){case'a':case'A':cout<<"Adition";break;case's':case'S':cout<<"Subtraction";break;default:cout<<"error";}cout<
6、ostream.h>inta(intn,ints)//无法解决正负交替的表示,使用参数{return(2*n-1)*s;}voidmain(){inti,n,s=0,sign=-1;cin>>n;for(i=1;i<=n;i++){s+=a(i,sign);sign=sign*-1;}cout<inta(intn){return(2*n-1)*(n%2==0?-1:1);}voidmain(){inti,n,s=0;cin>>n;for(i
7、=1;i<=n;i++){s+=a(i);}cout<voidmain(){inti,n,a;cin>>n;a=1;cout<inta(intn){if(n==1)return1;returna(n-1)+n;}voidmain(){in
8、ti,n;cin>>n;for(i=1;i<=n;i++){cout<voidexch(float&x,float&y){floatz;z=x;x=y;y=z;}voidmain(){floatheight1,height2,height3;cin>>height1>>height2>>height3;if(height2>he
9、ight1)exch(height1,height2);//第二个数比第一个小if(height3>height2)exch(height2,height3);//最后一个最小if(height2>height1)exch(height1,height2);cout<10、#includevoidmain(){charc;cin>>c;switch(c){case'a':case'A':cout<<"Adition";break;case's':case'S':cout<<"Subtraction";break;default:cout<<"error";}cout<
10、#includevoidmain(){charc;cin>>c;switch(c){case'a':case'A':cout<<"Adition";break;case's':case'S':cout<<"Subtraction";break;default:cout<<"error";}cout<
此文档下载收益归作者所有