首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++菜鸟,今天学会了fabs函数的用法

2012-05-03 
C++初学者,今天学会了fabs函数的用法#include iostream#include cmathusing namespace stdint main()

C++初学者,今天学会了fabs函数的用法
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double k,r,s;
double tsin(double x);
cout<<"r=";
cin>>r;
cout<<"s=";
cin>>s;
if (r*r<=s*s)
k=sqrt(tsin(r)*tsin(r)+tsin(s)*tsin(s));
else 
k=tsin(r*s)/2;
cout<<k<<endl;

}
 double tsin(double x)
 {
double p=1e-6,g=0,t=x;
int n=1;
do 
{
g=g+t;
n++;
t=-t*x*x/(2*n-1)/(2*n-2);
} while (fabs(t)>=p);//fabs函数用来求绝对值的
return g;
 }

[解决办法]
楼主好强,fabs是什么函数,我怎么没听说过~~~

热点排行