小编Mus*_*fat的帖子

C 编程中根据给定边求三角形的角度

我在我的 code::blocks 中运行它来显示三角形的 3 个角度,其中 3 条边由用户给出。但如果我运行并给出 3 个边,例如 3,4,5,输出将是 -1.#J -1.#J -1.#J。我的代码有什么问题吗?

#include <stdio.h>
#include <math.h>

int main()
{
    float a, b, c, A, B, C, R, s, pi, area;
    pi = acos(-1);

    scanf("%f %f %f", &a, &b, &c);
    s = (a+b+c)/2;
    area = sqrt(s*(s-a)*(s-b)*(s-c));

    R = (a*b*c)/(4*area);

    A = (180/pi)*asin(a/2*R);
    B = (180/pi)*asin(b/2*R);
    C =  (180/pi)*asin(c/2*R);

    printf("%.2f %.2f %.2f", A, B, C);


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c math

3
推荐指数
1
解决办法
8871
查看次数

标签 统计

c ×1

math ×1