Write a program to find the area of triangle by sides (Heron's Formula)

 

 GTU PPS Practical-2

Logic :

Logic of this program is very simple as everyone knows the basic mathematics to find area of triangle.
Let us quickly recall the formula of the area of a triangle.
Area of triangle (A) = [s(s-a)(s-b)(s-c)]^½
In this program, we have to take the length of sides of a triangle from the user then calculate s = (a+b+c)/2 and then we can calculate the area of triangle.
Here, we have to use math.h library to take square root.

Let's look at the algorithm.

Algorithm :

  1. START
  2. Input sides a, b, c of triangle.
  3. Compute s = (a+b+c)/2.
  4. Compute ar = s*(s-a)*(s-b)*(s-c) .
  5. Take area = square root of ar .
  6. print area.
  7. STOP

Code :

#include <stdio.h>
#include <math.h>
int main()
{
float a,b,c,s,area;
printf("Enter the length of side a:");
scanf("%f", &a);
printf("Enter the length of side b:");
scanf("%f", &b);
printf("Enter the length of side c:");
scanf("%f", &c);
s = (a+b+c)/2 ;
area = s*(s-a)*(s-b)*(s-c) ;
printf("The area of given triangle is %.2f", sqrt(area));
return 0;
}

Output :

Here you can see output screen of the code.You can get this type of output if you write above code.

c-program-to-find-area-of-triangle-by-heron-formula




Also check

THANK YOU 

Post a Comment

0 Comments