Problem Description
Write a program to calculate the perimeter of a triangle using Heros formula
Use the Following Formula:
s = (a+b+c)/2
area = sqrt(s*(s-a)*(s-b)*(s-c))
Input and Output Format:
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.Test Case 1
Input (stdin)2.0 3.0 4.0
Expected Outputperimeter of triangle is=2.904737
Test Case 2
Input (stdin)3.4 5.6 7.9
Expected Outputperimeter of triangle is=8.178576
Program
#include <stdio.h>
#include<math.h>
int main()
{
float a,b,c,s,area;
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("perimeter of triangle is=%f",area);
return 0;
No comments:
Post a Comment