Basic C Program to find area of triangle

    In this C program we will see how to find the Area of triangle using formula:

Area = √ s (s-a) (s-b) (s-c) , here s = semi-perimeter = a+b+c /2 and a, b, c are sides of triangle.

 

C program to find area of triangle

  • LOGIC: 

 First we'll calculate semi-perimeter and then we'll find area using the formula. Since formula of area have square root, so we'll include  <math.h>  file in our program.

 

  • ALGORITHM:
  1. Start
  2. Input three sides of triangle: a, b, c.
  3. Calculate semi-perimeter, s = a+b+c /2
  4. Calculate area of triangle, area = √s (s-a) (s-b) (s-c)
  5. Print the area of triangle
  6. End
  • CODE:
#include <stdio.h>
#include <math.h>

int main ()
{
    /*declare variables for 3 sides,
    semi-perimeter and area.*/
    float a,b,c,s,area;
    printf("Enter sides of triangle : ");
    //input values of 3 sides from user.
    scanf("%f %f %f",&a,&b,&c);

    //calculate semi-perimeter
    s=(a+b+c)/2;
    //calculate area
    area=sqrt(s*(s-a)*(s-b)*(s-c));

    printf("Area of the triangle is : %.2f",area);

    return 0;
  •  OUTPUT:

Enter sides of triangle : 3 4 5
Area of the triangle is : 6.00

 

  • CHALLENGE.1:

Try to make a program to find sum of roots and product of roots of a quadratic equation.

Solution to above Challenge.1


That's it for today. If you have any problem then don't hesitate to ask.

Share, Subscribe and keep coding...

 


Comments