Write a program in C which is a Menu-Driven Program to compute the area of the various geometrical shape.
#include <stdio.h>
int main()
{
int shape;
float base, length, breadth, height, area, radius;
printf(” 1 –> Square\n”);
printf(” 2 –> Rectangle\n”);
printf(” 3 –> Triangle\n”);
printf(” 4 –> Circle\n”);
printf(“Enter the Figure code: “);
scanf(“%d”, &Shape_Code);
switch(Shape_Code)
{
case 1:
printf(“Enter the Side: “);
scanf(“%f”, &length);
area = length * length;
printf(“Area of the Square=%.2f\n”, area);
break;
case 2:
printf(“Enter Length and Breadth:\n”);
scanf(“%f %f”, &length,&breadth);
area = breadth * length;
printf(“Area of the Rectangle = %.2f\n”, area);
break;
case 3:
printf(“Enter the Base and Height:\n”);
scanf(“%f %f”, &base, &height);
area = 0.5 * base * height;
printf(“Area of the Triangle = %.2f\n”, area);
break;
case 4:
printf(“Enter the Radius: “);
scanf(“%f”, &radius);
area = 3.142 * radius * radius;
printf(“Area of the Circle = %.2f\n”, area);
break;
default:
printf(“Error in Shape code\n”);
break;
}
return 0;
}
Output:
1 –> Square
2 –> Rectangle
3 –> Triangle
4 –> Circle
Enter the Figure code: 3
Enter the Base and Height:
6
9
Area of the Triangle =27.00