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

2025-04-30 04:24:54
推荐回答(4个)
回答1:

我只会C语言.
# include
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);
好了。

回答2:

c++版吧:
#include
#include
using namespace std;
int main(){
double a;
cin>>a;
cout< return 0;
}

a就是那个角度;
sin cos tan 都是在cmath中的函数;

如果想自己求不用头文件的话;可以看看高等数学书。

回答3:

#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));
}

回答4:

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