No. one
先定义a为最大值,让b或者c与其比较得出……
#include<iostream>
using namespace std;
//编写一个c程序,输入a,b,c三个值,输出其中最大者。
int main()
{
int a,b,c,max;
cin>>a>>b>>c;
max=a;
if(b>max&&b>c)
{
max=b;
cout<<max<<endl;
}
else if(c>max&&c>b)
{
max=c;
cout<<max<<endl;
}
else
{
cout<<max<<endl;
}
return 0;
}
No. two
这是最基础的方法:
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
int max;
if(a>b)
{
max=a;
}
else
{
max=b;
}
if(max<c)
{
max=c;
}
cout<<max<<endl;
return 0;
}
No.three
利用简单好理解的条件运算符也可以的哈哈
#include<iostream>
using namespace std;
//利用条件运算符求三个数中的最大者max
int main()
{
int a,b,c;
cin>>a>>b>>c;
int max;
max=(a>b?a:b);
max=(a>c?a:c);
max=(b>c?b:c);
cout<<max<<endl;
return 0;
}
暂且就这几种吧!想到了会再补充的😊