C program to find Areas of triangle, square,circle,rectangle,parallelogram

#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:
 {
  float radius,area;
  printf("Enter Radius of Circle\n");
  scanf("%f",&radius);
  area=(float)3.14159*radius*radius;
  printf("Area of Circle with radius %f is %f\n",radius,area);
  break;
 }
 case 4:
 {
  float len,breadth,area;
  printf("Enter Length and Breadth of Rectangle\n");
  scanf("%f %f",&len,&breadth);
  area=(float)len*breadth;
  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:-
Enter
1 for Triangle
2 for Square
3 for Circle
4 for Rectangle
5 for Parallelogram
1
Enter sides of triangle
1
1
1
Area of Triangle with sides 1,1,1 is 0.433013

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post