circle ,rectangle,square and triangle using switch case

/*write a program to calculate the area of circle ,rectangle,square and triangle in one program with using switch case /*

#include
#include
void main()
{
int a=0,b,pi=3.14,r,h,n;
clrscr();
printf("enter r:");
scanf("%d",&r);
printf("enter b:");
scanf("%d",&b);
printf("enter h:");
scanf("%d",&h);
printf("\nenter 1 for circle\nenter 2 for square\nenter 3 for rectangle\nenter 4 for triangle\n");
printf("enter choice:");
scanf("%d",&n);

switch (n)
{
case 1:
a=pi*r*r;
printf("area of circle is %d",a);
break;
case 2:
a=4*b;
printf("area of square is %d",a);
break;
case 3:
a=2*b*h;
printf("area of rectangle is %d",a);
break;
case 4:
a=(b/2)*h;
printf("area of triangle is %d",a);
break;
default:
printf("bug");
break;
}
getch();
}

17 comments:

Sagar Nandwani said...

i think you should check the logic of program accepting data before option is not correct logic.

Unknown said...

true

Unknown said...

true

Unknown said...

its too long..

Unknown said...

you should use float instead of int
coz answer of circle and triangle area cant be in integer

Unknown said...

Float expressions are not allowed in switch case

Unknown said...

True

Logeshwaran J said...

Where is output?. .

sarathkumar said...

Output

sarathkumar said...

Output

PUBG said...

Poke you

PUBG said...

Yeah that's true bae

GKRread said...

Out put

GKRread said...

Out put

Unknown said...

Output

Unknown said...

your program is right but the formula is of perimeter or circumference not area.

Unknown said...

Output

Post a Comment