#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;
}
函数的重载
最新推荐文章于 2022-03-02 21:02:40 发布