Thursday, September 13, 2018

TRIANGULAR AREA

  • Problem Description

    Tom has a homework.His maths teacher gave homework in solving a area problem in mathematics.Help Tom in finding area of triangle of sides a,b,c by writing a code.

    A method for calculating the area of a triangle when you know the lengths of all three sides.

    Let a,b,c be the lengths of the sides of a triangle. The area is given by: Heron's formula


    Heron was one of the great mathematicians of antiquity and came up with this formula sometime in the first century BC, although it may have been known earlier. He also extended it to the area of quadrilaterals and higher-order polygons

    Input:
    Input should contain three sides a,b,c
    Output:
    Should display the area of triangle in sq.units
  • CODING ARENA
  • #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("Area=%.4f",area);
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    5 6 7
    
    
    Expected Output
    Area=14.6969
  • Test Case 2

    Input (stdin)
    10 5 7
    
    
    Expected Output
    Area=16.2481

No comments:

Post a Comment