Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int fig_code;
float radius ; /* For Circle */
float length , breadth ; /* For Rectangle */
float base , height ; /* For Triangle */
float side ; /* For Square */
float base1 , height1 ; /* For parallelogram */
float base2 , base3 , height2 ; /* For Trapezoid */
printf("1 Circle\n");
printf("2 Rectangle\n");
printf("3 Triangle\n");
printf("4 Square\n");
printf("5 Parallelogram\n");
printf("6 Trapezoid\n");
printf(" Enter the Figure code\n");
scanf("%d" , &fig_code\n");
switch(fig_code)
{
printf("Enter the Radius\n");
scanf("%f" , &radius);
Area= 3.142*radius*radius;
printf("Area of Circle = %f\n" , Area);
break;
scanf("%f%f" ,&breadth, &length);
Area= breadth*length;
printf("Area of Rectangle = %f\n" , Area);
break;
scanf("%f%f" , &base , &height);
area= 0.5*base*height;
printf("Area of Triangle = %f\n" , area);
break;
scanf("%f" , &side);
area= side*side;
printf("Area of Square = %f\n" , area);
break;
scanf("%f%f" , &base1 , &height1 );
Area= base1 * height1;
printf("Area of Parallelogram = %f\n" , Area);
break;
case 6:
printf("Enter the base2 , base3 and height2\n");
scanf("%f%f" , &base1 , &base2 , &height1 );
Area=0.5*( base1 + base2 ) * height2;
printf("Area of Trapezoid = %f\n" , Area);
break;
default:
printf("Error in the figure code\n");
break;
} /* End of switch */
} /* End of main() */
Output:
....................
1 Circle
2 Rectangle
3 Triangle
4 Square
5 Parallelogram
6 Trapezoid
5 Parallelogram
6 Trapezoid
....................
Enter the Figure Code
4
Enter the side
2
2
Area of a square = 4
Did you check the following? C Program: Make a Calculator by using switch Statement |
0 Response to "C Program: Make a Calculator that Calculates Area of different Figures by using switch Statement"
Post a Comment