#include <iostream>
using namespace std;
int main(){
//求两数中的大者?
int a,b;
cin>>a>>b;
if(a>b)
cout<<"The max number is:"<<a;
else
cout<<"The max number is:"<<b;
}
method two:
#include <iostream>
using namespace std;
int main(){
//求两数中的大者?
int a,b,max;
cin>>a>>b;
if(a>b)
max=a;
else
max=b;
cout<<"The max number is:"<<max;
}
本文提供了两个使用C++编程语言实现的简单示例,用于找出两个输入数字中的最大值。第一个示例直接使用if-else语句进行比较并输出结果;第二个示例则引入了一个变量来保存最大值,并最终输出该变量。
908

被折叠的 条评论
为什么被折叠?



