Q:

Write a c program using switch case to calculate the area of circle,square and rectangle

0

Write a c program using switch case to calculate the area of circle,square and rectangle

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#include<stdio.h>
#include<conio.h>
int main()
{
	int n;
	float rad,area,nsq,length,breadth;
	printf("enter any number\n");
	scanf("%d",&n);
	switch(n)
	{
		case 1:
			printf("\nplease enter the radius of the circle\n");
			scanf("%f",&rad);
			area=3.14*rad*rad;
			printf("\nArea of circle: %f",area);
	    break;
	    
	    case 2:
	    	printf("please enter the lenght of side of the square:");
			scanf("%f",&nsq);
			area=nsq*nsq;
			printf("\nArea of rectangle: %f",area);
			
	    	
	    break;
	    
	    case 3:
	    		printf("please enter the lenght  of the rectangle:");
	    		scanf("%f",&length);
	    		printf("enter the breadth of the rectangle:");
	    		scanf("%f",&breadth);
	    		area=length*breadth;
	    		printf("\nArea of rectangle: %f",area);
	    break;
	    
	    default:
	    	printf("invalid choice");
	}
	
}

Output:

enter any number
1

please enter the radius of the circle
3

Area of circle: 28.260000
enter any number
2
please enter the lenght of side of the square:4

Area of rectangle: 16.000000
enter any number
3
please enter the lenght  of the rectangle:4
enter the breadth of the rectangle:3

Area of rectangle: 12.000000

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Programming Exercises With Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
write program in c to calculate volume using funct... >>
<< write a c program demonstrate to call by reference...