C Conditional Statement: Exercise-14 with Solution
Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene.
Equilateral triangle: An equilateral triangle is a triangle in which all three sides are equal. In the familiar Euclidean
geometry, equilateral triangles are also equiangular; that is, all three internal angles are also congruent to each
other and are each 60°.
Isosceles triangle: An isosceles triangle is a triangle that has two sides of equal length.
Scalene triangle: A scalene triangle is a triangle that has three unequal sides, such as those illustrated above.
Test Data :
Input three sides of triangle: 50 50 60
Expected Output :
This is an isosceles triangle.
Sample Solution :-
C Code:
#include <stdio.h>
int main()
{
int sidea, sideb, sidec; //are three sides of a triangle
/*
* Reads all sides of a triangle
*/
printf("Input three sides of triangle: ");
scanf("%d %d %d", &sidea, &sideb, &sidec);
if(sidea==sideb && sideb==sidec) //check whether all sides are equal
{
printf("This is an equilateral triangle.\n");
}
else if(sidea==sideb || sidea==sidec || sideb==sidec) //check whether two sides are
equal
{
printf("This is an isosceles triangle.\n");
}
else //check whether no sides are equal
{
printf("This is a scalene triangle.\n");
}
return 0;
}
Flowchart :
C Conditional Statement: Exercise-15 with Solution
Write a C program to check whether a triangle can be formed by the given value for the angles.
Test Data :
Input three angles of triangle : 40 55 65
Expected Output :
The triangle is not valid.
Sample Solution :-
C Code:
#include <stdio.h>
void main()
{
int anga, angb, angc, sum; //are three angles of a triangle
printf("Input three angles of triangle : ");
scanf("%d %d %d", &anga, &angb, &angc);
/* Calculate the sum of all angles of triangle */
sum = anga + angb + angc;
/* Check whether sum=180 then its a valid triangle otherwise not */
if(sum == 180)
{
printf("The triangle is valid.\n");
}
else
{
printf("The triangle is not valid.\n");
}
Flowchart :