
正文
c语言中的sin函数 c语言中的sin函数如何使用?
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
C语言编写sin函数?求教!
1.
C语言中要编写sin函数c语言中的sin函数,实质上要利用sinc语言中的sin函数的泰勒公式,然后根据泰勒公式,将其中的每一项进行分解,最后用循环,累加计算出最终结果
2.
下面用for循环实现sin的算法,程序代码如下c语言中的sin函数:
#includestdio.h
#includemath.h
void
main()
{
int
i;
float
x,sum,a,b;
//sum代表和,a为分子,b为分母
char
s;
printf("please
input
x");
scanf("%f",x);
s=1;
sum=0;
a=x;
//分母赋初值
b=1;
//分子赋初值
for(i=1;a/b=1e-6;i++)
{
sum=sum+s*a/b;
//累加一项
a=a*x*x;
//求下一项分子
b=b*2*i*(2*i+1);
//求下一项分母
s*=-1;
}
printf("sum=%f\n",sum);
}
3.
关于上述程序的几点说明:上述程序的计算结果精确到小数点后六位c语言中的sin函数;上述程序运用了sin的泰勒展开式
sin
x=x-x^3/3!+x^5/5!
......
,程序中将sin泰勒公式中的每一项拆成了分子,分母以及每一项前的符号这三项,以便于每一项的累加
相关问答
Q1: c语言中sin怎么输入?
输入一个double类型的数,调用c标准库中的sin函数即可。
函数原型:double
sin(double
x);
功能:
函数用来求给定值的正弦值
头文件:#include
math.h
参数:给定的值(弧度)。
返回值:返回-1
至1
之间的计算结果。
示例:
#includestdio.h
#includemath.h
int main()
{
const double PI = 3.1415926;
double d;
scanf("%lf", d);
double result = sin(d*PI/180)+cos(d*PI/180);
printf("%f\n",result);
return 0;
}
Q2: c语言中sin是啥?
C语言sin()用来计算参数x c语言中的sin函数的正玄值c语言中的sin函数,然后将结果返回。返回-1 至1 之间的计算结果。
例子c语言中的sin函数:
#include math.h
main(){
double answer = sin(0.5);
printf("sin(0.5) = %f\n", answer);
}
执行
sin(0.5) = 0.479426
C语言sin():
sin()原型:double sin(double x)
sin()角度与弧度:
π=180°
1°=π/180
1(rad)=180/π
角度转弧度:用角度乘以π/180
弧度转角度:用弧度乘以180/π,或者用rtod()函数
扩展资料:
与sin相似的acos函数
函数名: acos
功 能:计算并返回arccos(x)值、要求-1=X=1
函数与形参类型:
double acos(x)
double x;
程序例:
#include stdio.h
#include math.h int main(void)
{
double result;
double x = 0.5; result = acos(x);
printf("The arc cosine of %lf is %lf\n", x, result);
return 0;
}
参考资料:CSDN博客频道-C语言中sin和cos的用法
Q3: C语言里sin函数和cos函数的调用
C语言里sin函数和cos函数是C标准数学函数库中c语言中的sin函数的函数c语言中的sin函数,调用需要引入math.h头文件。
一、sin() 函数描述:
C 库函数 double sin(double x) 返回弧度角 x c语言中的sin函数的正弦。sin() 函数的声明:double sin(double x)。
参数:x -- 浮点值,代表了一个以弧度表示的角度。
返回值:该函数返回 x 的正弦。
二、cos() 函数描述:
cos() 函数的功能是求某个角的余弦值。cos() 函数的声明:double cos(double x)。
参数:x -- 浮点值,代表了一个以弧度表示的角度。
返回值:该函数返回 x 的余弦。
扩展资料:
相关的三角函数:
double asin (double); 结果介于[-PI/2,PI/2]
double acos (double); 结果介于[0,PI]
double atan (double); 反正切(主值),结果介于[-PI/2,PI/2]
double atan2 (double,double); 反正切(整圆值),结果介于[-PI,PI]
参考资料来源:百度百科-math.h
c语言中的sin函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语言中的sin函数如何使用?、c语言中的sin函数的信息别忘了在本站进行查找喔。







