This program is used to print the area of the triangle by the co-ordinates of its 3 points.suppose points are A(x1,y1),B(x2,y2) and C(x3,y3) then the area is given by:
Here in this program we have multiplied ans2 by -1 if ans2<0 because the area of any this is never less then 0 so in formula also we have written x1(y2-y3)+x2(y3-y1)+x3(y1-y2) in mode and the use of mode is to convert negative value to positive value and positive value remains positive only.
Program:
/*PROGRAMMER: AADARSH SOJITRA
DATE:26/8/2013*/
#include<stdio.h>
#include<conio.h>
main()
{
float x1,x2,x3,y1,y2,y3,ans,ans2,ans3;
clrscr();
printf("\n\t This program will calculate the area of triangle in plane");
printf("\n\n\t\t put comma between two cordinates");
printf("\n Enter x1,y1:");
scanf("%f,%f",&x1,&y1);
printf("\n Enter x2,y2:");
scanf("%f,%f",&x2,&y2);
printf("\n Enter x3,y3:");
scanf("%f,%f",&x3,&y3);
ans2=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
if(ans2<0)
{
ans3=ans2*(-1);
ans=ans3/2;
printf("\n\tArea of triangle is %.3f",ans);
}
else
{
ans=ans2/2;
printf("\n\tArea of triangle is %.3f",ans);
}
getch();
}
Program:
/*PROGRAMMER: AADARSH SOJITRA
DATE:26/8/2013*/
#include<stdio.h>
#include<conio.h>
main()
{
float x1,x2,x3,y1,y2,y3,ans,ans2,ans3;
clrscr();
printf("\n\t This program will calculate the area of triangle in plane");
printf("\n\n\t\t put comma between two cordinates");
printf("\n Enter x1,y1:");
scanf("%f,%f",&x1,&y1);
printf("\n Enter x2,y2:");
scanf("%f,%f",&x2,&y2);
printf("\n Enter x3,y3:");
scanf("%f,%f",&x3,&y3);
ans2=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
if(ans2<0)
{
ans3=ans2*(-1);
ans=ans3/2;
printf("\n\tArea of triangle is %.3f",ans);
}
else
{
ans=ans2/2;
printf("\n\tArea of triangle is %.3f",ans);
}
getch();
}