Write a C program to calculate the area of a triangle, square and circle.

First open CodeBlocks and create a file.Then save the file named test.cpp.Then write the following simple C code.Finally Run the Code.

Code:


#include<stdio.h>
#include<conio.h>

int main()
{
float b,c,d;
char a;

printf("TO Calculate the area of a TRIANGLE Press 't'\n");
printf("TO Calculate the area of a SQUARE Press 's'\n");
printf("TO Calculate the area of a CIRCLE  Press 'c'\n\n");
a=getch();

if(a=='t')
{
printf("Enter the value of Height & Base in cm:\n");
scanf("%f%f",&b,&c);
d=.5*b*c;
printf("The area of Triangle is : %.2f",d);
}

else if(a=='s')
{
printf("Enter the value of arm in cm : \n");
scanf("%f",&b);
d=b*b;
printf("The area of Square is :  %.2f",d);
}
else if(a=='c')
{
printf("Enter the radius of the Circle in cm :\n");
scanf("%f",&c);
d=3.14*c*c;
printf("The area of Circle is : %.2f",d);
}
else
{
 printf("Please enter correct letter!");
}
return 0;
}

Output: