Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, July 16, 2022

C program to test whether the triangle is right angled or not

 C program to test whether the triangle is right-angled or not




C program to test whether the triangle is right-angled or not

Introduction:


Triangles are an essential shape in geometry and have a wide range of applications in various fields. A right-angled triangle is a triangle in which one of the angles measures 90 degrees. In this article, we will explore how to write a C program to test whether a given triangle is right-angled or not.



Understanding Right-Angled Triangles


A right-angled triangle is a type of triangle that has one angle that measures exactly 90 degrees. The other two angles are acute (less than 90 degrees) and add up to 90 degrees. The side opposite the right angle is called the hypotenuse, while the other two sides are called the legs.

The Pythagorean Theorem

The Pythagorean theorem is a fundamental theorem in geometry that relates to right-angled triangles. It states that the square of the length of the hypotenuse is equal to the sum of the squares of the lengths of the two legs.

The theorem can be written as follows:

c² = a² + b²

where c is the length of the hypotenuse, and a and b are the lengths of the legs.

We can write a C program that takes the lengths of the three sides of a triangle as input and outputs whether the triangle is right-angled or not.

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the three sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
if(a+b==90||a+c==90||b+c==90)
printf("The triangle is right-angled.");
else
printf("The triangle is not right-angled");
return 0;
}

Output:




Conclusion:



In conclusion, writing a C program to test whether a given triangle is right-angled or not is a simple and effective way to solve this problem. By using the Pythagorean theorem, we can easily determine if a given triangle is right-angled or not. The C program provided in this article can be used as a reference to solve similar problems in the future. We hope that this article has provided you with valuable insights into writing C programs to test whether a triangle is right-angled or not.


FAQs


1) What is a right-angled triangle? 
Ans: A right-angled triangle is a type of triangle that has one angle that measures exactly 90 degrees.

2) What is the Pythagorean theorem? 
Ans: The Pythagorean theorem is a fundamental theorem in geometry that relates to right-angled triangles. It states that the square of the length of the hypotenuse is equal to the sum of the squares of the lengths of the two legs.

3) How can we use the Pythagorean theorem to check for right-angled triangles? 
Ans: We can use the Pythagorean theorem to check for right-angled triangles by checking whether any of the three conditions are satisfied: c² = a² + b², a² = b² + c², or b² = a² + c².

4) Why is it important to know whether a triangle is right-angled or not? 
Ans: Knowing whether a triangle is right-angled or not is important in various fields such as engineering, architecture, and physics. Right-angled triangles have special properties that make them useful in solving problems involving angles and distances.

5) Can we use the C program to check for right-angled triangles for triangles with non-integer side lengths? 
Ans: Yes, the C program can be modified to accept non-integer side lengths by changing the data type of the input variables from int to float or double. However, the program would need to be modified to handle floating-point arithmetic, which can be more complex than integer arithmetic.

Also Read:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages