Menu Driven Program for Area coderinme

Menu Driven Program for Area

Menu Driven Program for Area
Using switch case, we can easily write a menu driven program. It will calculate the area of triangle, square, rectangle, circle on the basis of user’s choice. He can exit the program by selecting the exit option.
So we code in the following way.

#include<stdio.h>
#define PI 3.14
int main()
{
int l,b,h,r,ch;
float area;
do
{
printf("\n1 for the area of Triangle\n");
printf("2 for the area of Square\n");
printf("3 for the area of Rectangle\n");
printf("4 for the area of Circle\n");
printf("5 for Exit\n");
printf("Enter your choice: ");
scanf("%d",&ch);

switch(ch)
{
case 1 :
printf("\nEnter the base of the triangle: ");
scanf("%d",&b);
printf("Enter the height of the triangle: ");
scanf("%d",&h);
area = ( b * h ) / 2;
printf("\nThe area of the triangle: %.2f sq. unit\n",area);
break;
case 2 :
printf("\nEnter the side of square: ");
scanf("%d",&l);
area = l * l;
printf("\nThe area of the Square: %.2f sq.unit\n",area);
break;
case 3 :
printf("\nEnter the length of the rectangle: ");
scanf("%d",&l);
printf("Enter the breadth of the rectangle: ");
scanf("%d",&b);
area = ( b * l );
printf("\nThe area of the Rectangle: %.2f sq. unit\n",area);
break;
case 4 :
printf("\nEnter the radius of the circle: ");
scanf("%d",&r);
area = PI * r * r;
printf("\nThe area of the Circle: %.2f sq. unit\n",area);
break;
case 5:
break;
default : printf("\nSorry!!!,Your chice is not correct\n");
}
}
while (ch != 5);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Menu Driven Program for Area

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.