C语言高手进~三角函数问题

来源:百度知道 编辑:UC知道 时间:2024/09/25 10:28:44
定义一个简单的三角函数计算问题 编译能通过 但是结果老是不对 在VC++6.0上运行的。请哪位高手给看一下哪里有错,谢谢啦~~

程序如下
#include "stdafx.h"
#include "math.h"
#define PI 3.1415
int main(int argc, char* argv[])
{ float a,b,c,d;
float triangle(float x,float y,float z); // claim the sub funtion
printf("sir input the value:\n");
scanf("%f,%f,%f",&a,&b,&c);
d=triangle(a,b,c);
printf("the value is %f",d);
return 0;
}

float triangle(float x,float y,float z)
{ float q;
q=(sin(x*PI/180)+sin(y*PI/180))/tan(z*PI/180);
return(q);

}
貌似与定义变量的数据类型有关 能详细解释一下最好 可以追加分数~~

你的程序没有问题

vc6.0 编译
q=(sin(x*PI/180)+sin(y*PI/180))/tan(z*PI/180);处出现
warning:“e:\c\bhj\bhj.cpp(16) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data”

这是因为sin 和 tan的 返回值是双精度double类型。把它赋值给 float q,就会丢失数据。
但是计算结果是基本正确的。如果想更精确计算 就把所有的 float 全部改成 double

$(word)

实验了下 是对的啊~