C语言 编写三角形面积计算

/*计算三角形面积*/
#include <stdio.h>
double sin(double x);
#define PI 3.14159265
int main()
{
double a, b, ang_c, s;

scanf("%lfa=3%lfb=4%lfc=45", &a, &b, &ang_c);
s = a * b * sin(ang_c * PI / 180.0) / 2.0;
printf("The area is %f\n", s);
return 0;
}
————————————————————————————————————————————————————————————————————————————————————————————
Linking...
求三角形面积.obj : error LNK2001: unresolved external symbol "double __cdecl sin(double)" (?sin@@YANN@Z)
Debug/求三角形面积.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
求三角形面积.exe - 2 error(s), 0 warning(s)

求助

#include <stdio.h>

#include <math.h>

//double sin(double x);

#define PI  3.14159265

int main()

{

 double a, b, ang_c, s;

 

 scanf("%lf %lf %lf", &a, &b, &ang_c);

 s = a * b * sin(ang_c * PI / 180.0) / 2.0;

 printf("The area is %f\n", s);

 return 0;

}

/*

要不然自己实现sin函数,否则引进math头文件

还有scanf 仔细看看,我怎么写的

*/

 

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-21
sin函数是数学公式,他的头文件你没有写
加上#include <math.h>即可

把double sin(double x);这个去掉,这个sin是头文件中的库函数,不必要自己编写
第2个回答  2013-09-21
1、加上头文件#include <math.h>
2、你的程序的输入部分scanf("%lfa=3%lfb=4%lfc=45", &a, &b, &ang_c);应该改为

scanf("%lf%lf%lf", &a, &b, &ang_c);,scanf函数中的格式串一般不可以添加除了格式串之外 的,比如a=3 b=4 c=45之类的
3、你用的面积公式是S = 1/2 * a * b * sin(a与b的夹角),sin(ang_c * PI / 180.0)这个部分我不理解 你的夹角怎么求的。如果你是输入三条边的长度,你可以使用海伦公式

S = 【(P* (P - a) * (P - b) * ( P - c))】的平方根 ,其中P为三角形的周长P = a + b + c
第3个回答  2013-09-21

第4个回答  2020-10-18
相似回答