Pages

Labels

C Program to calculate perimeter and area of triangle with 3 sides

This programs find the perimeter and area of triangle by asking 3 sides length values

#include <stdio.h>
#include <math.h>
int main () {
  float a, b, c, s, peri, area;
  printf ("Enter the 1st side:");
  scanf ("%f", &a);
  printf ("Enter the 2nd side:");
  scanf ("%f", &b);
  printf ("Enter the 3rd side:");
  scanf ("%f", &c);
  peri = a + b + c;
  s = peri / 2;
  area = (s * (s - a) * (s - b) * (s - c)) pow (1 / 2);
  or sqrt (s * (s - a) * (s - b) * (s - c));
  printf ("The perimeter of triangle is:%f\n", peri);
  printf ("The area of triangle is:%f\n", area);
}

Output:
Enter 1st side: 4.0
Enter 2nd side: 5.0
Enter 3rd side: 6.0
The perimeter of triangle is: 15.0
The area of triangle is: 9.9

How it works
It asks for 3 sides length values and calculate area and perimeter of triangle with math formula.

Followers