This C program finds the area of Triangle using 2 methods. This is a part of Mumbai University MCA College C Programs MCA Sem 1.
The area of triangle can be found by knowing its height and width or by knowing the length of all side.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{ clrscr();
float bs,ht,a,b,c,s;
float area;
int k;
printf("If you want to use base n height method then enter 1\n");
printf("If you want to use sides method then enter 2\n");
printf("Enter your choice:");
scanf("%d",&k);
switch(k)
{
case 1:
printf("Enter the base and the height of the triangle:");
scanf("%f%f",&bs,&ht);
area=0.5*bs*ht;
break;
case 2:
printf("Enter the three sides of the triangle:");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
break;
}
printf("The area of the triangle is:%f",area);
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
No comments:
Post a Comment