#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;
}
Enter the lengths of threesides of a triangle:10
12
13
Triangle can be drawn
It is a scalene Triangle
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.