Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

n C language , write a program to calculate the area of various shapes based on

ID: 3897357 • Letter: N

Question

n C language , write a program to calculate the area of various shapes based on the choice from the user.

the program should provide the user with a menu to select from

R-for retangle

T-for trapezoid

C-for circle

E-for end

the program should ask the for the proper input for every particular shape

A sample output may look like

This can fined the area of the following shapes :

R-rectangle

T-Trapezoid

C-Circle

E-End

Select your choice (R,T,C or E to end : R

Enter length : 50

Enter height : 20

The area of the rectangle is 1000.00 m^2

-------------------------------------------------------------------------

This can fined the area of the following shapes :

R-rectangle

T-Trapezoid

C-Circle

E-End

Select your choice (R,T,C or E to end : T

Enter base 1 : 20

Enter base 2 : 10

Enter height : 5

The area of the trapezoid is 75.00 m^2

-------------------------------------------------------------------------

This can fined the area of the following shapes :

R-rectangle

T-Trapezoid

C-Circle

E-End

Select your choice (R,T,C or E to end : C

Enter radius : 50

The area of the circle is 7857.14 m^2

-------------------------------------------------------------------------

This can fined the area of the following shapes :

R-rectangle

T-Trapezoid

C-Circle

E-End

Select your choice (R,T,C or E to end : e

---------------------------------------------------------------

This can fined the area of the following shapes :

R-rectangle

T-Trapezoid

C-Circle

E-End

Select your choice (R,T,C or E to end : x

Invalid choice

Explanation / Answer

#include <stdio.h>

int main(void) {

char option;
float length,height,area,a,b,h,radius;

printf(" R-rectangle");
printf(" T-Trapezoid");
printf(" C-Circle");
printf(" E-End");
printf(" Select your choice (R,T,C or E to end : ");
scanf(" %c",&option);

switch(option)
{
case 'R' :
printf(" Enter length : ");
scanf("%f",&length);
printf(" Enter height : ");
scanf("%f",&height);
area = length*height;
printf(" The area of the rectangle is %.2f m^2",area);
break;

case 'T' :
printf(" Enter base 1 : ");
scanf("%f",&a);
printf(" Enter base 2 : ");
scanf("%f",&b);
printf(" Enter height : ");
scanf("%f",&h);
area = (a+b)*h/2;
printf(" The area of the trapezoid is %.2f m^2",area);

case 'C' :
printf(" Enter radius : ");
scanf("%f",&radius);
area = 3.14*radius*radius;
printf(" The area of the circle is %.2f m^2",area);

case 'E' :
printf(" Enter Axis A : ");
scanf("%f",&a);
printf(" Enter Axis B : ");
scanf("%f",&b);
area = 3.14*a*b;
printf(" The area of the ellipse is %.2f m^2",area);

default :
printf(" Invalid choice");

}

return 0;
}

Output:

R-rectangle
T-Trapezoid
C-Circle
E-End
Select your choice (R,T,C or E to end :R
Enter length :50
Enter height :20
The area of the rectangle is 1000.00 m^2

Do ask if any doubt. Please upvote.