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

已知X=0度、100度、20度。。。180度,求sinx、cosx和tanx。
谁能用循环做。我用循环输出的有负值,搞不懂。

第1个回答  2009-04-04
我只会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);
好了。
第2个回答  2009-04-04
c++版吧:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a;
cin>>a;
cout<<sin(a)<<'\t'<<cos(a)<<'\t'<<tan(a)<<endl;
return 0;
}

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

如果想自己求不用头文件的话;可以看看高等数学书。
第3个回答  2009-04-04
#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个回答  2009-04-04
我觉得提问者应该是要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])
....
第5个回答  2009-04-04
#include<stdio.h>
#include<math.h>
main()
{
int x=0,y=100,z=20,k=180;
printf("%f\n",sin(x));
...
}
相似回答