函数的重载

#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;




}

猜你喜欢

转载自blog.csdn.net/laizhuocheng/article/details/79944498