#include
using namespace std;
int add(int a,int b)
{
return a+b;
}
long int add(long int a,long int b)
{
return a+b;
}
float add(float a,float b)
{
return a+b;
}
double add(double a,double b)
{
return a+b;
}
int main()
{
int i1,i2,i;
long int l1,l2,l;
float f1,f2,f;
double d1,d2,d;
cout<<“请输入两个int类型:”<<endl;
cin>>i1>>i2;
i=add(i1,i2);
cout<<i<<endl;
cout<<“请输入两个long int类型:”<<endl;
cin>>l1>>l2;
l=add(l1,l2);
cout<<l<<endl;
cout<<“请输入两个float类型:”<<endl;
cin>>f1>>f2;
f=add(f1,f2);
cout<<f<<endl;
cout<<“请输入两个double类型:”<<endl;
cin>>d1>>d2;
d=add(d1,d2);
cout<<d<<endl;
return 0;
}
两数求和 用C++语言编写求两个数之和的函数,要求使用函数重载,能求整数、长整型、浮点、双精度等数的和。
最新推荐文章于 2025-01-10 00:15:00 发布