这道程序用C语言或C++怎么写?

来源:百度知道 编辑:UC知道 时间:2024/06/07 00:55:26
已知X=0度、100度、20度。。。180度,求sinx、cosx和tanx。
谁能用循环做。我用循环输出的有负值,搞不懂。

#include "stdio.h"
#include "math.h"
main()
{
float x,pi=3.1416;/*pi的值根据需要取精确位数。*/
printf("请输入度数:");
scanf("%f",&x);
x=x*pi/180;
printf("sinx=%f;cosx=%f;tanx=%f",sin(x),cos(x),tan(x));
}

#include<stdio.h>
#include<math.h>
main()
{
int x=0,y=100,z=20,k=180;
printf("%f\n",sin(x));
...
}

我只会C语言.
# include <math.h>
main()
{
int a;
doublt b;
printf("输入你知道的度数a\n");
scanf("%d",&a);
b=cos(a);
printf("求出的值为%lf\n",b);
getch();
}
sinx tanx, 是一样的,只是换一下就行了.
函数是一样的,也是sin(a);tan(a);
好了。

我觉得提问者应该是要sin(),cos()和tan()现的源代码吧。直接调用math.h,还需要问么?不过,这些数值函数的实现都是用asm和C的混编代码来实现的。如double sin(double x)的代码大概是这样子。
static unsigned short NANTRIG[4] = {0, 0, 0x0420, 0x7FF0);
asm FLD DOUBLE(x)