从键盘输入三个整数,赋值给整型变量a、b和c,编写程序求3个数中的最大值。

如题所述

/*
**算法思路:定义一个变量max,初始默认最大值为a,然后将b、c分别与max做大小比较,如果比当前max大,则
将自身赋值给max,否则不做任何操作。
*/
#include <stdio.h>
int max(int a,int b,int c)
{
int max=a;  //初始默认最大值为变量a
if(max<b)   //将当前最大值与b最比较
b=max;
if(max<c) //将当前最大值与c最比较
max=c;
return max;  //返回最大值
}
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c); //输入a,b,c的值
printf("a,b,c三个数中的最大值为: %d\n",max(a,b,c));  //调用函数max
return 0;
}

示例运行结果:

36 25 72

a,b,c三个数中的最大值为: 72

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-09-25
#include <iostream>
using namespace std;
int main()
{
int a,b,c,max;
cout<<"inputa,b,c:"<<endl;
cin>>a;
cin>>b;
cin>>c;
max = a;
if(max<b)
max = b;
if(max<c)
max = c;
cout<<"最大值:"<<max<<endl;
return 0;
}

追问

java

追答public static int max(int x,int y,int z){
int max=x;
if(y>max){
max=y;}
if(z>max){
max=z;}
return max;
}

 这是一个函数,你自己调用一下就好了

本回答被网友采纳