C program to find area of different shapes is a program to find the area of different shapes such as triangle, circle, square, etc.

How to find the area of shapes?
To find an area of shapes we use different mathematical formulas having for different shapes.

Area of shapes formulas :
1. Formula to calculate the area of a triangle :-
Area of triangle = (height * base)/2
2. Formula to calculate the area of a rectangle :-
Area of rectangle = (length * breadth)
3. Formula to calculate the area of a square :-
Area of square = (side * side)
4. Formula to calculate the area of a circle :-
5. Formula to calculate the area of a parallelogram :-
Area of parallelogram = (base * height)

Page Contents

## Algorithm to calculate area of shapes

1. Take a choice shape from a user which user want to find an area
2. Write a switch case to find an area of different shapes.
If Case matches
Calculate the area of a shape
Print area of a shape
break
Else
break

## C program to find area of different shapes

```#include<stdio.h>

#include<math.h>

main()

{

int choice;

printf("Enter\n1 for Triangle\n2 for Square\n3 for Circle\n4 for Rectangle\n5 for Parallelogram\n");

scanf("%d",&choice);

switch(choice)

{
case 1:

{
int a,b,c;

float s,area;

printf("Enter sides of triangle\n");

scanf("%d %d %d",&a,&b,&c);

s=(float)(a+b+c)/2;

area=(float)(sqrt(s*(s-a)*(s-b)*(s-c)));

printf("Area of Triangle with sides %d,%d,%d is %f\n",a,b,c,area);

break;

}

case 2:

{

float side,area;

printf("Enter Sides of Square\n");

scanf("%f",&side);

area=(float)side*side;

printf("Area of Square is %f\n",area);
break;

}

case 3:

{

break;

}
case 4:

{

printf("Enter Length and Breadth of Rectangle\n");

printf("Area of Rectangle is %f\n",area);

break;

}
case 5:

{

float base,height,area;

printf("Enter base and height of Parallelogram\n");

scanf("%f %f",&base,&height);

area=(float)base*height;

printf("Enter area of Parallelogram is %f\n",area);

break;
}

default:

{

printf("Invalid Choice\n");

break;
}

}

}```

Output : 