Tag Archives: area

Finding the area of geometric shapes

This program displays a menu and makes use of switch-case statement to process the selected option.

/*This program finds the area of some basic geometric shapes*/

#include<stdio.h>
#include<conio.h>
void main()
{
	int op=0,l=0,b=0,r=0,h=0,area=0;
	clrscr();
	printf("Find Area of the following:\nSelect an option[1,2,3,4]:\n");
	printf("1.Square\n");
	printf("2.Rectangle\n");
	printf("3.Circle\n");
	printf("4.Triangle\n");
	scanf("%d",&op);
	switch(op)
	{
		case 1:
		  printf("Enter side:");
		  scanf("%d",&l);
		  area=l*l;
		  printf("Area:%d",area);
		  break;
		case 2:
		  printf("Enter length:");
		  scanf("%d",&l);
		  printf("Enter breadth:");
		  scanf("%d",&b);
		  area=l*b;
		  printf("Area:%d",area);
		  break;
		case 3:
		  printf("Enter radius:");
		  scanf("%d",&r);
		  area=3.14*r*r;
		  printf("Area:%d",area);
		  break;
		case 4:
		  printf("Enter base:");
		  scanf("%d",&b);
		  printf("Enter height:");
		  scanf("%d",&h);
		  area=0.5*b*h;
		  printf("Area:%d",area);
		  break;
		default:
		  printf("Please select an option from the above list");
	}
	getch();
}

Output

Find Area of the following:
Select an option[1,2,3,4]:
1.Square
2.Rectangle
3.Circle
4.Triangle
1
Enter side:8
Area:64