Using Switch statement to create a Menu Driven program to calculate Area of different shapes.
Language : C
[sourcecode language='c']
// To calculate area of circle, rectangle and triangle by switch case.
# include
# include
int ch,r,a,h,d,l;
float Ac, Ar, At;
void main()
{
clrscr();
printf(“\n press1,area of circle”);
printf(“\n press2,area of rectangle”);
printf(“\n press3,area of triangle”);
printf(“\n enter your choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1: printf(“\n enter values to find area of circle”);
scanf (“%d”,&r);
Ac = 3.14*r*r;
printf(“\n area of circle is %f”,Ac);
break;
case 2: printf(“\n enter values to find area of rectangle “);
scanf(“%d%d”,&a,&h);
Ar= a*h;
printf(“\n area of rectangle is %f”,Ar);
break;
case 3: printf(“\n enter values to find volume of cylinder”);
scanf(“%d%d”,&d,&l);
At = 0.5*d*l;
printf(“\n area of triangle is %f”,At);
break;
DEFAULT: printf(“\n enter the proper choice”);
}
getch();
}
[/sourcecode]






