【C++函数重载】求3个数中最大的数…
2016-03-02 17:28
399 查看
#include
using
namespace
std;
int
main( )
{
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
i1,i2,i3,i;
cin>>i1>>i2>>i3; //输入3个整数
i=max(i1,i2,i3); //求3个整数中的最大者
cout<<"i_max="<<i<<endl;
double d1,d2,d3,d;
cin>>d1>>d2>>d3; //输入3个双精度数
d=max(d1,d2,d3); //求3个双精度数中的最大者
cout<<"d_max="<<d<<endl;
long
g1,g2,g3,g;
cin>>g1>>g2>>g3; //输入3个长整数
g=max(g1,g2,g3); //求3个长整数中的最大者
cout<<"g_max="<<g<<endl;
}
int
max(int a,int
b,int c) //定义求3个整数中的最大者的函数
{
if(b>a) a=b;
if(c>a) a=c;
return
a;
}
double max(double a,double
b,double c)//定义求3个双精度数中的最大者的函数
{
if(b>a) a=b;
if(c>a) a=c;
return
a;
}
long
max(long a,long
b,long c) //定义求3个长整数中的最大者的函数
{
if(b>a) a=b;
if(c>a) a=c;
return
a;
}
using
namespace
std;
int
main( )
{
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
i1,i2,i3,i;
cin>>i1>>i2>>i3; //输入3个整数
i=max(i1,i2,i3); //求3个整数中的最大者
cout<<"i_max="<<i<<endl;
double d1,d2,d3,d;
cin>>d1>>d2>>d3; //输入3个双精度数
d=max(d1,d2,d3); //求3个双精度数中的最大者
cout<<"d_max="<<d<<endl;
long
g1,g2,g3,g;
cin>>g1>>g2>>g3; //输入3个长整数
g=max(g1,g2,g3); //求3个长整数中的最大者
cout<<"g_max="<<g<<endl;
}
int
max(int a,int
b,int c) //定义求3个整数中的最大者的函数
{
if(b>a) a=b;
if(c>a) a=c;
return
a;
}
double max(double a,double
b,double c)//定义求3个双精度数中的最大者的函数
{
if(b>a) a=b;
if(c>a) a=c;
return
a;
}
long
max(long a,long
b,long c) //定义求3个长整数中的最大者的函数
{
if(b>a) a=b;
if(c>a) a=c;
return
a;
}
相关文章推荐
- 【c++】用c++编写的求任意区间的素…
- 构造函数
- #include<bits/stdc++.h>
- C++中ShallowCopy和DeepCopy的区别
- VC++中窄字节、宽字节、多字节
- 项目开发中值得推荐的C/C++框架和库总结
- 第1章 软件工程基本原理和C++类
- C++调用lib或dll文件
- 【C语言】输入一组整数,求出这组数字子序列和中最大值
- 黑马程序员-C语言回顾-指针
- 类(Classes)的定义与实现
- Effective C++ 笔记:4设计与声明
- C语言学习
- C++中字符串字面值和字符相加
- c语言:用递归方法求n的阶乘
- C语言表达式和运算符(三)
- Effective c++ 读书笔记
- Find the Kth number c++ version
- C++中在容器Vector中使用结构体Struct
- c++重写string类