Mega Code Archive

 
Categories / C / Beginners
 

Program to find the type of the triangle made by i-p values

of its coordinates of its vertices #include <stdio.h> #include <conio.h> #include <math.h> #include<stdlib.h> 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(" These coordinates can't represent a 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(" HAVE 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(" 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(); }