Experiment 3-8 Output the area and circumference of a triangle (15 points)

This question requires writing a program to calculate and output the area and perimeter based on the three sides a, b, and c of the input triangle. Note: In a triangle, the sum of any two sides is greater than the third side. The formula for calculating the
area of ​​a triangle: area=√​s(s−a)(s−b)(s−c), where s=(a+b+c)/2.

Input format: The
input is 3 positive integers, representing the 3 sides a, b, and c of the triangle.

Output format:
If the input side can form a triangle, in one line, follow

area = area; perimeter = perimeter
output format, with two decimal places. Otherwise, output

These sides do not correspond to a valid triangle
Input example 1:
5 5 3
Output example 1:
area = 7.15; perimeter = 13.00
Input example 2:
1 4 1
Output example 2:
These sides do not correspond to a valid Triangle
topic collection complete works portal

#include <stdio.h>
#include <math.h>
int main()
{
    
    
    float a, b, c, s;
    scanf("%f %f %f", &a, &b, &c);
    s = (a + b + c) / 2;
    if (a + b > c && a + c > b && b + c > a)
        printf("area = %.2f; perimeter = %.2f", sqrt(s * (s - a) * (s - b) * (s - c)), 2 * s);
    else
        printf("These sides do not correspond to a valid triangle");

    return 0;
}

Guess you like

Origin blog.csdn.net/fjdep/article/details/112934452
Recommended