C++中输入两个或三个数,然后输出最大的数

C++中输入两个或三个数,然后输出最大的数
如何让程序自行比较输入的两个数还是三个数,然后比大小,而不是让用户选择是比较两个还是三个,也就是说只要用户输入两个或者三个数马上就能出现结果,而不是以下方式判断:
省略部分内容
couta;
if (a==2)
{max();}
if (a==3)
{max();}
有点类似于:
if(cin>>a>>b>>c)
{}
目前写到这样
#include
using namespace std;
int Max(int m,int n)
{
return m>n?m:n;
}
int Max(int m,int n,int o)
{
int a=m>n?m:n;
int b=a>o?a:o;
return b;
}
double Max(double m,double n)
{
return m>n?m:n;
}
double Max(double m,double n,double o)
{
double c=m>n?m:n;
double d=c>o?c:o;
return d;
}
int main()
{
int n;
int i=0;
double a,b,c;
cout >b>>c)
{
}
if(cin>>a>>b)
{
}
return 0;
}
冰与火的故事 1年前 已收到1个回答 举报

一缕阳光GY 幼苗

共回答了18个问题采纳率:100% 举报

#include
#include
#include
using namespace std;
int max(int a,int b,int c)
{
return a>b?a>c?a:c:b>c?b:c;
}
int main()
{
string line;
getline(cin,line);
int count=0;
int a[3]={0};
istringstream ss(line);
while(count>a[count])++count;
cout

1年前 追问

7

冰与火的故事 举报

拜托关键部位给个解释谢谢....

举报 一缕阳光GY

全是基础语法……
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.016 s. - webmaster@yulucn.com