Friday, 4 December 2015

Menu Driven Program to Find Area of Square, Rectangle And Circle

AIM
To write a menu driven program for finding the area of a square , rectangle , and a circle
ALGORITHM
Step 1: Start
Step 2: Print choice square , rectangle , circle
Step 3: if square ,else go to  step 7
Step 4: read side
Step 5: as*s
Step 6:Print a
Step 7:if rectangle,else go to step 11
Step 8: read length and breadth
Step 9: a←lenght*breadth
Step 10: print a
Step 11: if circle,else go to step15
Step 12: read radius
Step 13: aradius*radius*3.14
Step 14: print a
Step 15: print want to continue?
Step 16: if yes,go to step 1
Step 17: stop

PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
     char t,n,y,Y;
   float radius,side,length,breadth,pi;
    int ch;
    pi=3.14;
     do
   {
    printf("\nMENU\n1)Area of square\n2)Area of rectangle\n3)Area of circle\nEnter choice:");
    scanf("%d",&ch);
    switch (ch)
    {
        case 1:
        printf("Enter the value of side\n");
        scanf("%f",&side);
        printf("the area of the square= %f*%f=%f cm",side,side,side*side);
        break;
        case 2:
        printf("\nEnter the value of length\n");
        scanf("%f",&length);
        printf("\nEnter the value of breadth\n");
        scanf("%f",&breadth);
        printf("the area of the rectangle= %f*%f=%f cm",length,breadth,length*breadth);
        break;
        case 3:
        printf("\nEnter the value of radius");
        scanf("%f",&radius);
        printf("the area of the circle= %f*%f*pi=%f cm",radius,radius,radius*radius*pi);
        break;
        default:printf("INVALID CHOICE");
        break;
    }
        printf("\n\nDO YOU WANT TO CONTINUE:\nThen press y else n:");
        fflush(stdin);

 scanf("%c",&t);
   }
        while(t=='y'||t=='Y');
        getch();
}
RESULT
The menu driven program for finding the area of a square , rectangle , and a circle was written , executed and the output  verified successfully.


OUTPUT

Menu Driven Program to Find Area of Square, Rectangle And Circle

No comments:

Post a Comment