switch case program in C Language

 

C program to display area of geometric shapes using switch case

/*********************************************

 C program to display area of geometric shapes using switch case

 ***************************************************/

#include<stdio.h>

#include<conio.h>

void main()

{

    int choice;

    int r,l,b,base,height,s,area;

clrscr();

    printf("Enter your choices as mentioned below to display area of geometric shapes\n");

    printf("For Area of circle : 1\n");

    printf("For Area rectangle : 2\n");

    printf("For Area of triangle : 3\n");

    printf("For Area of square : 4\n");

    printf("Enter your choice to perform operation\n");

    scanf("%d",&choice);

    switch(choice)

    {

        case 1:

        printf("Enter radius to calculate area of circle\n");

        scanf("%d",&r);

        area=3.14*r*r;

        printf("The area of circle is:%d\n",area);

        break;

        case 2:

        printf("Enter length and breadth to calculate area of rectangle\n");

        scanf("%d%d",&l,&b);

        area=l*b;

        printf("The area of rectangle is:%d\n",area);

        break;

        case 3:

         printf("Enter base  and height to calculate area of triangle\n");

        scanf("%d%d",&base,&height);

        area=0.5*base*height;

        printf("The area of triangle is:%d\n",area);

        break;

        case 4:

        printf("Enter side  to calculate area of square\n");

        scanf("%d",&s);

        area=s*s;

        printf("The area of square is:%d\n",area);

        break;

        default:

        printf("The choice is invalid, please enter valid choice\n");

        break;

    }

    printf("End of program");

    

}


Enter your choices as mentioned below to display area of geometric shapes

For Area of circle : 1

For Area rectangle : 2

For Area of triangle : 3

For Area of square : 4

Enter your choice to perform operation

5

The choice is invalid, please enter valid choice

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या