Program to find the type of the triangle made by input or given values of its coordinates of its vertices in c.

Program to find the type of the triangle made by input or given values of its coordinates of its vertices in c.



#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("Enter coordinates of vertex B(x & y respectively)... ");
scanf("%f%f",&x2,&y2);
printf("Enter coordinates of vertex C(x & y respectively)... ");
scanf("%f%f",&x3,&y3);
if ((x1==x2 && x2==x3)||(y1==y2 && y2==y3))
{
printf("Sorry ..These coordinates can't represent any triangle.");
printf("A,B & C are colinear & thus consitute a line.");
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("These coordinates can't represent a triangle.");
printf("A,B & C are colinear & thus consitute a line.");
printf("Thanks Good 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("Length of side AB is = %f",c);
printf("Length of side BC is = %f",a);
printf("Length of side CA is = %f",b);
if (a==b==c)
printf("Triangle made by these vertices is an Equilateral Triangle.");
else if (a==b||b==c||c==a)
{
if (a==b==c);
else
printf("Triangle made by these vertices is an Isosceles Triangle.");
}
else if (a!=b && b!=c && c!=a)
printf("Triangle made by these vertices is a scalene triangle.");
getch();
}

2 comments:

  1. Is that a C program or C++?

    ReplyDelete
  2. These tow libraries conio.h, maths.h are not recognised in gcc.

    ReplyDelete