Find triangle is equilateral,isosceles or right angled Code in C Language
Write a C program to Find triangle is equilateral,isosceles or right angled by accepting the length of three sides of a triangle from input and then test and print the type of triangle.
Program will test the type of triangle is equilateral, isosceles, right angled or none of these and print the output to screen.Program will use the basic mathematics formulas of trigonometric to test type of triangle.
Find triangle is equilateral,isosceles or right angled code
#include “stdio.h” void main() { int i, j; int temp; int sides[3]; int type; int isRightAngled; clrscr(); printf(“Please enter the three sides of triange\n”); for(i = 0; i < 3; i++) { scanf(“%d”, &sides[i]); } for(i = 0; i < 3; i++) { for(j = i + 1; j < 3; j++) { if(sides[i] > sides[j]) { temp = sides[i]; sides[i] = sides[j]; sides[j] = temp; } } } type = 3; isRightAngled = 0; if(sides[2] > sides[0] + sides[1]) /*check if triangle is valid */ type = 0; else if(sides[0] == sides[2]) type = 1; else { if(sides[0] == sides[1]) type = 2; if(sides[2] * sides[2] == sides[0] * sides[0] + sides[1] * sides[1]) isRightAngled = 1; } switch(type) { case 0: printf(“The triangle is Invalid\n”); break; case 1: printf(“The triangle is Equilateral Triangle\n”); break; case 2: if(isRightAngled == 1) printf(“The triangle is Isosceles and Right Angled Triangle\n”); else printf(“The triangle is Isosceles Triangle\n”); break; case 3: if(isRightAngled == 1) printf(“The triangle is Scalene and Right Angled Triangle\n”); else printf(“The triangle is Scalene Triangle\n”); break; } getch(); }