
main()
{
int a,b,c,d,e,max;
printf("请输入五个数\n");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
max=a;
(max>b)(max):(max=b);
(max>c)(max):(max=c);
(max>d)(max):(max=d);
(max>e)(max):(max=e);
printf("max=%d",max);
}
这个就是了,你可以运行一下。从cmd出运行,编译好之后在cmd中用路径打开那个程序就行了
#include
<stdioh>
int
max(int
a,int
b){return
a>ba:b;}/此函数返回最大值/
int
main()
{
int
n1,n2,n3;
printf("请输入三个整数,以空格分隔:");
scanf("%d%d%d",&n1,&n2,&n3);
printf("max
int=%d\n",max(max(n1,n2),n3));
return
0;
}
结果
wh@wh-ubuntu704:~$
vim
test5c
wh@wh-ubuntu704:~$
cc
-o
test5
test5c
wh@wh-ubuntu704:~$
/test5
请输入三个整数,以空格分隔:3
9
5
max
int=9
时间匆忙,写得不完善,已经实现了你的要求
#include<iostream>
using namespace std;
template<class T>
class MAX
{
private:
T x,y,z,max;
public:
MAX(T a,T b,T c)
{
x=a;y=b;z=c;
}
T max1(T a,T b,T c)
{
if(a>=b&&a>=c) return a;
else if(b>=c) return b;
else return c;
}
};
void main()
{
int a,b,c;
cout<<"请输入三个整数:"<<endl;
cin>>a>>b>>c;
MAX<int> m1(a,b,c);
cout<<"三个数中的最大值为:"<<m1max1(a,b,c)<<endl;
float p,q,r;
cout<<"请输入三个小数:"<<endl;
cin>>p>>q>>r;
MAX<float> m2(p,q,r);
cout<<"三个数中的最大值为:"<<m2max1(p,q,r)<<endl;
}
以上就是关于求五个数中最大值的c程序全部的内容,包括:求五个数中最大值的c程序、请问 怎样用C语言求三个数的数的最大值 具体的运行的程序是怎样的、C++:用类模板编写求 3个数中最大值的程序.等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)