#include<iostream> //预操作
#include<cmath>
using namespace std;// 使用命名空间std
double sroot(int a)
{
return (sqrt(a));
}
double sroot(long b)
{
return (sqrt(b));
}
double sroot(double c)
{
return sqrt(c);
}
int main()
{
int a = 5;
long b = 1234;
double c = 10.99;
cout << "a的平方根为:" << sroot(a) << endl;
cout << "b平方根为:" << sroot(b) << endl;
cout << "c的平方根为:" << sroot(c) << endl;
system("pause");
return 0;
}C++:建立一个被称为sroot()的函数,返回其参数的二次方根。重载sroot()3次,让它返回整数、长整数与双精度的二次方根
最新推荐文章于 2022-05-03 14:15:12 发布
本文介绍了一个简单的C++程序,该程序通过重载函数sroot()实现了对整数、长整型和浮点数三种不同数据类型的平方根计算,并展示了如何使用cmath库中的sqrt()函数来获取这些值。
7182

被折叠的 条评论
为什么被折叠?



