Menu Driven C program to calculate Area of Square, Rectangle
This program demonstrates the use of switch() case :
OUTPUT :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int ch;
float s,l,b;
float arect,asquare;
clrscr();
do
{
printf("\t Main Menu\n");
printf("\t 1. Area of Rectangle.\n");
printf("\t 2. Area of Square.\n");
printf("\t 3. Exit\n");
printf("\n\tEnter your choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1 : printf("\n\tEnter length and bredth:\n");
scanf("%f%f",&l,&b);
arect=l*b;
printf("\n\tArea of rectangle is : %f\n\n",arect);
break;
case 2 : printf("\n\tEnter side of the Square:\n");
scanf("%f",&s);
asquare=s*s;
printf("\n\tArea of Square is : %f\n\n",asquare);
break;
case 3 : exit(0);
}
}
while(ch>=1 && ch<=4);
}
OUTPUT :
Main Menu
1. Area of Rectangle.
2. Area of Square.
3. Exit
Enter your choice:
1
Enter length and bredth:
2
4
Area of rectangle is : 8.000000
Main Menu
1. Area of Rectangle.
2. Area of Square.
3. Exit
Enter your choice:
3
1. Area of Rectangle.
2. Area of Square.
3. Exit
Enter your choice:
1
Enter length and bredth:
2
4
Area of rectangle is : 8.000000
Main Menu
1. Area of Rectangle.
2. Area of Square.
3. Exit
Enter your choice:
3
Comments
Post a Comment