Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views5 pages

C Programs4

The document provides C programming exercises to classify triangles based on their sides and angles. It includes code examples for determining if a triangle is equilateral, isosceles, or scalene, as well as checking the validity of a triangle based on the sum of its angles. Test data and expected outputs are also provided for both exercises.

Uploaded by

Debabrata Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

C Programs4

The document provides C programming exercises to classify triangles based on their sides and angles. It includes code examples for determining if a triangle is equilateral, isosceles, or scalene, as well as checking the validity of a triangle based on the sum of its angles. Test data and expected outputs are also provided for both exercises.

Uploaded by

Debabrata Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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 :

You might also like