C++——求3个数中最大的数(分别考虑整数、双精度数、长整数数的情况),用函数重载方法。

没注释的源代码

#include <iostream>

using namespace std;

int max(int a,int b,int c);

double max(double a,double b,double c);

long max(long a,long b,long c);

int main()

{

int a,b,c;

double x,y,z;

long m,n,p;

cout<<"请输入三个整数:";

cin>>a>>b>>c;

cout<<"三个整数的最大值是:"<<max(a,b,c)<<endl;

cout<<"请输入三个浮点数:";

cin>>x>>y>>z;

cout<<"三个浮点数的最大值是:"<<max(x,y,z)<<endl;

cout<<"请输入三个长整数:";

cin>>m>>n>>p;

cout<<"三个长整数的最大值是:"<<max(m,n,p)<<endl;

return 0;

}

int max(int a,int b,int c)

{

if(b>a) a=b;

if(c>a) a=c;

return a;

}

double max(double a,double b,double c)

{

if(b>a) a=b;

if(c>a) a=c;

return a;

}

long max(long a,long b,long c)

{

if(b>a) a=b;

if(c>a) a=c;

return a;

}

相关推荐
橙子也要努力变强12 分钟前
信号捕捉底层机制-机理篇2
linux·服务器·c++
foundbug99929 分钟前
自适应滤除直达波干扰的MATLAB实现
开发语言·算法·matlab
盐焗鹌鹑蛋32 分钟前
【C++】stack和queue类
c++
MegaDataFlowers1 小时前
206.反转链表
数据结构·链表
郝学胜-神的一滴1 小时前
罗德里格斯旋转公式(Rodrigues‘ Rotation Formula)完整推导
c++·unity·godot·图形渲染·three.js·unreal
lzh200409192 小时前
深入理解进程:从PCB内核结构到写时拷贝的底层实战
linux·c++
aseity2 小时前
跨平台项目中QString 与 非Qt 跨平台动态库在字符集上的一个实用的互操作约定.
c++·经验分享
CN-Dust2 小时前
【C++】while语句例题专题
数据结构·c++·算法
用户805533698032 小时前
现代Qt开发教程(新手篇)1.11——定时器
c++·qt
澈2072 小时前
STL迭代器:容器遍历的万能钥匙
开发语言·c++