1410 - C语言-最大值2

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

有三个整数a b c,由键盘输入,输出其中的最大的数。

题目输入

一行数组,分别为a b c

题目输出

a b c其中最大的数

输入/输出样例

输入格式

10 20 30

输出格式

30

C语言解答

#include<stdio.h>
int main()
{
	int a,b,c,max;
	scanf("%d%d%d",&a,&b,&c);
	max=a>b?a:b;
	max=max>c?max:c;
	printf("%d\n",max);
	return 0;
}

C++解答

#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
void change(int& x,int & y)
{
	int temp;
	temp=x;x=y;y=temp;
}
int main()
{
	//ifstream cin("aaa.txt");
	int i,j,n;
	int x,y,z;
cin>>x>>y>>z;
if(x<y) change(x,y);
if(x<z) change(x,z);	
cout<<x<<endl;
return 0;
}