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;

}

相关推荐
消失的旧时光-19434 分钟前
C++ 多态核心三件套:虚函数、纯虚函数、虚析构函数(面试 + 工程完全指南)
开发语言·c++·面试·虚函数·纯虚函数·虚析构函数
nglff6 分钟前
蓝桥杯抱佛脚第四天|前缀和,差分对应练习
算法·职场和发展·蓝桥杯
赵民勇15 分钟前
gtkmm库之GtkWindow与ApplicationWindow用法详解
linux·c++
freexyn23 分钟前
Matlab入门自学七十四:坐标系转换,直角坐标、极坐标和球坐标的转换
开发语言·算法·matlab
咱就是说不配啊30 分钟前
3.20打卡day34
数据结构·c++·算法
小张会进步35 分钟前
数组:二维数组
java·javascript·算法
佑白雪乐1 小时前
LCR 175. 计算二叉树的深度
算法·深度优先
阿Y加油吧1 小时前
力扣打卡day07——最大子数组和、合并区间
算法
Larry_Yanan1 小时前
Qt网络开发之基于 QWebEngine 实现简易内嵌浏览器
linux·开发语言·网络·c++·笔记·qt·学习
想吃火锅10051 小时前
【leetcode】105. 从前序与中序遍历序列构造二叉树
算法·leetcode·职场和发展