c++過載函式的簡單運用
阿新 • • 發佈:2019-02-05
#include<iostream> #include<cmath> using namespace std; int max1(int a , int b); int max1(int a , int b ,int c); double max1(double a , double b); double max1(double a , double b ,double c); int max1(int a , int b) { if(a>b) return a; else return b; } int max1(int a , int b ,int c) { if(a > b && a>c) return a; else if(b > a && b > c) return b; else return c; } double max1(double a , double b) { if(a>b) return a; else return b; } double max1(double a , double b ,double c) { if(a > b && a>c) return a; else if(b > a && b > c) return b; else return c; } int main(){ int a, b , c; cout<<"請輸入三個整數:" ; cin>> a>> b>> c; cout<<"請輸入三個雙精度數值:" ; double x, y ,z; cin>>x >> y>>z; cout<<max1(a,b)<<endl; cout<<max1(a, b, c)<<endl; cout<<max1(x , y)<<endl; cout<<max1(x , y ,z)<<endl; return 0; }