#include<stdio.h>
void main()
{
char user;
float area,l,b,h,w,r,pi=3.1416;
printf("To calculate the area of\n\nA triangle press 'a'\nA rectangle press 'b'\nA circle press 'c'\n\nInput here:");
scanf("%c", &user);
switch(user){
case 'a':{
printf("Base: ");
scanf("%f", &b);
printf("Height: ");
scanf("%f", &h);
area=0.5*b*h;
printf("Area of the triangle is %.2f square unit", area);
break;
}
case 'b':{
printf("Length: ");
scanf("%f", &l);
printf("Width: ");
scanf("%f", &w);
area=l*w;
printf("Area of the rectangle is %.2f square unit", area);
break;
}
case 'c':{
printf("Radius: ");
scanf("%f", &r);
area=pi*r*r;
printf("Area of the circle is %.2f square unit", area);
break;
}
default:
break;
}
}
Download source code
0 comments:
Post a Comment