函数---求三个数中的最大值
时间: 1ms 内存:128M
描述:
编写函数max,函数声明如下:
int max(int x,int y,int z); //求三个参数中的最大值的函数声明
在以下程序的基础上,添加max函数的定义,使程序能够正确执行。
提交时,只需要提交max函数的定义代码即可。
#include <iostream>
using namespace std;
int max(int x,int y,int z); //求三个参数中的最大值的函数声明
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<"max=";
cout<<max(a,b,c);
return 0;
}
输入:
三个整数
输出:
这三个整数中的最大值
示例输入:
3 6 4
示例输出:
max=6
提示:
参考答案(内存最优[548]):
program p1000(Input,Output);
var
a,b,c:integer;
begin
read(a, b, c);
if(a < b) then
a := b;
if(a < c) then
a := c;
writeln('max=',a);
end.
参考答案(时间最优[0]):
#include <iostream>
using namespace std;
int max(int x,int y,int z); //求三个参数中的最大值的函数声明
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<"max=";
cout<<max(a,b,c);
return 0;
}int max(int x,int y,int z)
{
int a;
if(x>y)
a=x;
else
a=y;
if(a>z)
return a;
else
return z;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。