租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

c语言怎么输出三角形面积和周长,c语言怎么输出空格

发布时间:2024-08-12 08:24:37

c语言怎样输出三角形面积和周长

要输出三角形的面积和周长,首先需要用户输入三角形的三条边长。然后根据输入的三边长计算三角形的面积和周长,最后将结果输出给用户。

以下是一个C语言程序示例,用于计算并输出三角形的面积和周长:

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

int main() {
    float side1, side2, side3;
    float perimeter, area, s;

    // 用户输入三角形的三条边长
    printf("Enter the length of side 1: ");
    scanf("%f", &side1);
    printf("Enter the length of side 2: ");
    scanf("%f", &side2);
    printf("Enter the length of side 3: ");
    scanf("%f", &side3);

    // 计算三角形的周长
    perimeter = side1 + side2 + side3;

    // 计算三角形的半周长
    s = perimeter / 2;

    // 计算三角形的面积
    area = sqrt(s * (s - side1) * (s - side2) * (s - side3));

    // 输出计算结果
    printf("Perimeter of the triangle: %.2f
", perimeter);
    printf("Area of the triangle: %.2f
", area);

    return 0;
}

通过上述程序,用户可以输入三角形的三条边长,程序会计算并输出该三角形的面积和周长。

tiktok粉丝购买:https://www.smmfensi.com/