[C++] 重载函数取最大值 →→→→→进入此内容的聊天室

来自 , 2021-04-15, 写在 C++, 查看 165 次.
URL http://www.code666.cn/view/95e6834d
  1. #include "stdafx.h"
  2. #include "iostream"
  3. using namespace std;
  4. int max1(int x, int y, int z)  //3个整数的最大值
  5. {      
  6.         int m;
  7.         int n;
  8.         if (x > y)m = x;
  9.         else m = y;
  10.         if (m > z)n = m;
  11.         else n = z;
  12.         return(n);
  13. }
  14. double max2(double a, double b,double c)//3个双精度数的最大值
  15. {
  16.         double mm;
  17.         double nn;
  18.         if (a>b)mm = a;
  19.         else mm = b;
  20.         if (mm>c)nn = mm;
  21.         else nn = c;
  22.         return(nn);
  23.  
  24. }
  25. int main()
  26. {
  27.         int x, y, z;
  28.         double a, b, c;
  29.         cout<<"input 3 integers"<<endl;
  30.         cin>>x>>y>>z;//输入3个整数
  31.         cout<<"最大值为"<<max1(x,y,z)<<endl;//输出其最大值
  32.         cout<<"input 3 doubles"<<endl;
  33.         cin>>a>>b>>c;//输入3个双精度数
  34.         cout<<"最大值为"<<max2(a, b, c)<<endl;//输出其最大值
  35.         return 0;
  36. }
  37.  

回复 "重载函数取最大值"

这儿你可以回复上面这条便签

captcha