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.

C Programming Language / Decision Making of C Language

2137

Program:

#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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.