EmbLogic's Blog

C program to compute area of triangle and square

#include
int main()
{
int area,triangle,side,base,height;
char ch;
printf(“Enter s for area and t for triangle:”);
scanf(“%c”,&ch);
switch(ch)
{
case ‘s’:
printf(“Enter side:”);
scanf(“%d”,&side);
area=side*side;
printf(“Area of square = %dm^2\n”,area);
break;
case ‘t’:
printf(“Enter base and hight:”);
scanf(“%d%d”,&base,&height);
area=(base*height)/2;
printf(“Area of triangle =%dm^2\n”,area);
}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>