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;

}

相关推荐
apcipot_rain1 小时前
C++转Java日记(04)
java·开发语言·c++
NEFU_Jyj2 小时前
牛客周赛R168
算法
WL学习笔记3 小时前
vector模拟实现
c++
蜗牛一步步往上爬6 小时前
第十六章 C++语言在深度学习中的应用
开发语言·c++·深度学习
likexuec8 小时前
数据结构(2)
数据结构
Navigator_Z9 小时前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
wo_jack9 小时前
C++ 入门笔记(十六):第16课 vector 模拟实现十问十答 —— 从三指针到迭代器失效
c++·后端·面试·stl·vector
D e re k ZH10 小时前
C++ 标准库算法全景指南
数据结构·c++·算法
冻柠檬飞冰走茶11 小时前
字母移动游戏题解:贪心求最长可保留连续子串(附 C 实现)
c语言·开发语言·数据结构·算法·动态规划