Menu Close

[Cprogm] Area of Triangle… FcukTheCode

Sajid loves super heroes he used to imagine himself to be a hero. One day his teacher was taking a class about shapes and asked the students to find the Area of the triangle using Heron’s formula. 

Sajid misheard this as Hero’s formula and was curious to discover the Hero’s formula for finding the area of the triangle.

Help Sajid to solve his math problem by using the correct logic in your code.
Functional Description:

Area = sqrt(s(s – a)(s – b)(s – c)), where 

s = (a + b + c) / 2 and 

a, b & c are the sides of triangle.

Input:
Input has 3 integers representing 3 side of the triangle

Output:
Print the area of the triangle with only two values after the decimal point
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c;
float s,area;
scanf("%d %d %d",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("%.2f\n",area);
	return 0;
}

INPUT_1:
5  5  4

OUTPUT:
9.17


INPUT_2:
6  5  4

OUTPUT:
6.48


INPUT_3:
10  15  20

OUTPUT:
60.79


INPUT_4:
22  23  20

OUTPUT:
185.90