您的位置:首页 > 其它

SDUT 1154 求三个整数的最大值

2017-06-25 23:06 176 查看

Problem Description

请编写程序,输入三个整数,求出其中的最大值输出。

Input

在一行上输入三个整数,整数间用逗号分隔。

Output

输出三个数中的最大值。

Example Input

5,7,9


Example Output

max=9


答案:

#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
int a, b, c, temp, max;
scanf("%d, %d, %d",&a, &b, &c);//使用C中的scanf输入函数可以达到输入之间逗号隔开
if(a > b)
temp = a;
else
temp = b;
if(temp > c)
max = temp;
else
max = c;
cout<<"max="<<max<<endl;
return 0;
}
或者是:(纯C++版本,但比较繁琐)
#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
int a, b, c, temp, max;
cin>> a;
if (cin.get()==',' ) //如果不按 数字+逗号+数字格式输入,则不允许输入第二个数,以达到限制要求      否则,用户输入数字+空格+数字也能达到输入两个数字
{
cin>>b ;
}
if (cin.get()==',' ) //如果不按 数字+逗号+数字格式输入,则不允许输入第二个数,以达到限制要求      否则,用户输入数字+空格+数字也能达到输入两个数字
{
cin>>c ;
}
if(a > b)
temp = a;
else
temp = b;
if(temp > c)
max = temp;
else
max = c;
cout<<"max="<<max<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐