C Source Codes List | Source Code Home
Program : Prg to find the type of the triangle made by i/p values of its coordinates of its vertices.
/* Prg to find the type of the triangle made by i/p values of its
coordinates of its vertices */
#include
#include
#include
#include
void main()
{
float x1,y1,x2,y2,x3,y3;
float a,b,c,m1,m2,m3;
clrscr();
printf("Enter coordinates of vertex A(x & y respectively):- ");
scanf("%f%f",&x1,&y1);
printf("\nEnter coordinates of vertex B(x & y respectively):- ");
scanf("%f%f",&x2,&y2);
printf("\nEnter coordinates of vertex C(x & y respectively):- ");
scanf("%f%f",&x3,&y3);
if ((x1==x2 && x2==x3)||(y1==y2 && y2==y3))
{
printf("\n\nThese coordinates can't represent a triangle.");
printf("\nA,B & C are colinear & thus consitute a line.");
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
exit(0);
}
else
{
m1=(y2-y1)/(x2-x1);
m2=(y3-y2)/(x3-x2);
m3=(y3-y1)/(x3-x1);
}
if (m1==m2||m2==m3||m3==m1)
{
printf("\n\nThese coordinates can't represent a triangle.");
printf("\nA,B & C are colinear & thus consitute a line.");
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
exit(0);
}
a = sqrt(pow((x2-x3),2) + pow((y2-y3),2));
b = sqrt(pow((x3-x1),2) + pow((y3-y1),2));
c = sqrt(pow((x2-x1),2) + pow((y2-y1),2));
printf("\n\nLength of side AB is = %f",c);
printf("\nLength of side BC is = %f",a);
printf("\nLength of side CA is = %f",b);
if (a==b==c)
printf("\n\nTriangle made by these vertices is an equilateral triangle.");
else if (a==b||b==c||c==a)
{
if (a==b==c);
else
printf("\n\nTriangle made by these vertices is an isosceles triangle.");
}
else if (a!=b && b!=c && c!=a)
printf("\n\nTriangle made by these vertices is a scalene triangle.");
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
}
C Source Codes List | Source Code Home
|
|