积累代码day1

比较大小的代码;

解法一:

#include<iostream>
using namespace std;
int main(){

 int a,b,c;
 cout<<"请输出两个整数:"<<"\n";
 cin>>a>>b;
 if(a>b)
 c=a;
 else
 c=b;
 cout<<"max="<<c<<"\n";
 
 
 return 0;
}

解法二:

#include<iostream>
using namespace std;
int main(){

 int a,b,t;
 cout<<"请输出两个整数:"<<"\n";
 cin>>a>>b;
 if(a<b)
 {

t=a;

a=b;

b=t


 cout<<"max="<<a<<"\n";
 
 
 return 0;
}


项目1;
分支结构程序设计体验

给定两个正整数,求出两个数 的正差值并输出

样例输入:             样例输出

7  20                        13

7    4                         3

#include<iostream>
using namespace std;
int main(){
 int a,b;
 cout<<"计算两个数的差"<<endl;
 cout<<"请输出2个整数:"<<"\n";
 cin>>a>>b;
 if(a>b)
 cout<<"两个数的差为:"<<a-b<<endl;
 else
 cout<<"两个数的差为:"<<b-a<<endl;
 
 
 
 
 
 return 0;
 }



项目二“:

输出四个正整数,输出其中的最大值

#include<iostream>
using namespace std;
int main(){
 int a,b,c,d,max;
 cout<<"请输出4个整数:"<<"\n";
 cin>>a>>b>>c>>d;
 
 max=a;
 if(max<b)
 {
  max=b;
  if(max<c)
     max=c;
 }
  else
  max=d;
 
cout<<"max="<<max<<endl; 
 
 
 return 0;

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值