网站建设资讯

NEWS

网站建设资讯

求正弦函数的值用c语言 求正弦函数的值用c语言表示

怎样用c语言编写一个程序用来输出正弦函数值

首先:程序应该这样改!

创新互联公司主要从事做网站、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务和顺,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

#include

#include

main()

{

double

n;

double

b,c;

scanf("%lf",n);

b=sin(n);

c=cos(n);

printf("%.2lf\n%.2lf",b,c);

return

0;

}

其次,这里的n是弧度值,你说的90度应该输入的是pi/2,而不是90,如果希望输入90的话,那就这样改!

#include

#include

main()

{

int

s;

double

n,b,c;

scanf("%d",s);

n=3.1415926*(s/180.0);

b=sin(n);

c=cos(n);

printf("%.2lf\n%.2lf",b,c);

return

0;

}

C语言sin怎么用

C语言sin()用来计算参数x

的正玄值,然后将结果返回。返回-1

至1

之间的计算结果。

例子:

#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的用法

C语言 求sin值

首先,你的测试输入和测试输出的数据是对应不上的,你写错信息了!

输入 3.1415026, 3 的时候,输出才是 -0.07522 。

好了,正确的参考代码如下:

#include stdio.h

double power(double x, int n); // 计算乘方的函数

double fact(int n);            //  计算阶乘的函数

int main(int argc, char const *argv[])

{

double x, s;

int n;

int sign = 1; //正负号开关变量,初始状态为正

printf("Please input a decimal number x , a postive int number n  :\n");

scanf("%lf%d", x, n);

for (int i = 0; i = n; i++)

{

s += sign * power(x, 2 * i + 1) / fact(2 * i + 1);

sign = -sign;

}

printf("x = %g, n = %d, s = %.5lf \n", x, n, s);

return 0;

}

//计算x^n

double power(double x, int n)

{

double p = 1;

//  这样的循环条件,很简洁。因为函数传入的是形参,也不会对main的变量造成影响。

for (; n--;)

{

p *= x;

}

return p;

}

//  计算n!

double fact(int n)

{

double f = 1;

//  这样的循环条件,很简洁。因为函数传入的是形参,也不会对main的变量造成影响。

for (; n;)

{

f *= n--;

}

return f;

}

测试截图:(分别测试了角度为 180度、90度、45度的弧度值)

输入和输出语句,你不想要这么多的提示信息的话,自己修改一下就可以了。

如有帮助,烦请点采纳,谢谢!


网页名称:求正弦函数的值用c语言 求正弦函数的值用c语言表示
文章URL:http://cdweb.net/article/hhchgc.html