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();
}

Related Links :

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


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!