Home / Programs / Get the lengths of three sides of a triangle. Check whether the triangle can be formed or not. If possible then classify the triangle as equilateral, isosceles or scalene. Otherwise, if the triangle cannot be formed give the user a chance to re-enter the lengths of the sides or terminate the program.
Programming Example

Get the lengths of three sides of a triangle. Check whether the triangle can be formed or not. If possible then classify the triangle as equilateral, isosceles or scalene. Otherwise, if the triangle cannot be formed give the user a chance to re-enter the lengths of the sides or terminate the program.

👁 2,242 Views
💻 Practical Program
📘 Step by Step Learning
Get the lengths of three sides of a triangle. Check whether the triangle can be formed or not. If possible then classify the triangle as equilateral, isosceles or scalene. Otherwise, if the triangle c

Program Code

#include <stdio.h>

int main(void)
{

	int sideOne,sideTwo,sideThree;
	char ans='y';
	while(ans=='y' ||ans=='Y')
	{
	printf("\n Enter the lengths of threesides of a triangle:");
	scanf("%d %d %d",&sideOne,&sideTwo,&sideThree);
	if(sideOne+sideTwo>sideThree && sideTwo+sideThree>sideOne 
                                    && sideOne+sideThree>sideTwo)
	  {
		printf("\n Triangle can be drawn");
		if(sideOne==sideTwo && sideTwo==sideThree)
			printf("\n It is a Equilateral Triangle");
		else if(sideOne==sideTwo || sideTwo==sideThree ||sideOne==sideThree)
				printf("\n It is a Isosceles Triangle");
			 else
			 	printf("\n It is a scalene Triangle");
		
		ans='n';
	
	  }
	else
	 {
		printf("\n Triangle cannot be drawn");
		printf("\n Do you want to reenter the lengths again(y/n)? ");
		fflush(stdin);
		scanf("%c",&ans);
	  }
      }
	getch();
	return 0;

}

Output


 Enter the lengths of threesides of a triangle:10
12
13

 Triangle can be drawn
 It is a scalene Triangle

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.