function overloading

#include<iostream>
using namespace std;
int fun(int a,int b);
double fun(double a,double b);
int fun(int a,int b)
{ if(a*b>0)
return abs(a-b);
if(a*b<0)
return abs(a)+abs(b);
}
double fun(double a,double b)
{ if(a*b>0) if(a>b) return a-b; else return b-a; if(a*b<0) if(a<0) return (-a)+b; else  return a+(-b); } void main() { // int a,b; //cin>>a>>b; //abs 返回的是整型  double不建议使用 cout<<fun(-9,5)<<endl<<fun(1.8,2.35)<<endl;





















}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324452287&siteId=291194637