谁会求三角形面积呀(C语言)

新手上路,请多包涵

Write a C program using MPI to calculate the area of a triangle. The process with the rank: 0 sends two floating point numbers for the base and height to all other processes. Each of these processes calculate the area of the triangle and display.

area = b * h/2

The following is just a sample dialog. Your program must work for any floating point number.

Enter two floating point numbers for the base and the height of a triangle.

10 12

Height = 12.00, base = 10.00

The area of the triangle is: 60.00

Height = 12.00, base = 10.00

The area of the triangle is: 60.00

Height = 12.00, base = 10.00

The area of the triangle is: 60.00

Height = 12.00, base = 10.00

The area of the triangle is: 60.00

阅读 2.1k
2 个回答

写一个选择结构,判断不同的三角形,在使用不计算方式推荐用海伦公式u=3116021265,2131144796&fm=173&app=25&f=JPEG.jfif

您好,这位同学,根据您的问题,我这边编写的算法如下:

//跟据输入的三角形的三条边判断三角形的类型,并输出其面积和类型。

#include <stdio.h>
#include<math.h>
int main(void)
{
    float a, b, c = 0;
    float s, square, i = 0;
    printf("请输入三个值,我判断是否是三角形");
    scanf("%f %f %f", &a, &b, &c);
    if (a + b > c && a + c > b && b + c > a)
    {
        s = a + b + c;
        i = s / 2;
        square = (float)sqrt(i * (i - a) * (i - b) * (i - c));

        if (a == b && a == c) {
            printf("三角形是等边三角形\n");
        }
        else if (a == b || a == c || b == c) {
            printf("三角形是等腰三角形\n");
        }
        else if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) {
            printf("三角形是直角三角形\n");
        }
        else {
            printf("三角形是普通三角形\n");
        }
        printf("三角形周长为%f ,面积为%f\n", s, square);

    }
    else {
        printf("这不是三角形");
    }



    return 0;
}

最后,我们来验证,根据验证,咱们的结果正确

真诚的希望我的回答能够帮到您和正遇到这个问题的其他同学

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进