about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Right Angle Triangle program in C++

 

 

 

Right angle triangle program is an important program in C++. We are going to develop a C++ program which will take three sides of triangle from user and after making decision will print on screen that triangle is right angled or not.

 

Logic

 

There is no rocket science or even there is even no logic in this program. This program is quite simple. We will use the Pythagoras theorem which states that

“If sum of square of two sides of triangle becomes equal to third side then triangle is right angle”

Hence if not becomes equal, then it is not right angle triangle.

We will implement the same logic of the Pythagoras statement in the conditional statement. We will take three variables namely a, b and c, store the sides of triangle in these variables. And start comparing, Is square of any side of triangle becomes equal to the square of sums of other two sides of triangles. Then triangle is right angle and on satisfying this condition the triangle is right angle will be print. On the other hand triangle is not right angle triangle will be print.

 

 

Code

 

#include<iostream>

using namespace std;

int main()

{

            int a,b,c;

            cout<<"Enter three sides of triangle\n";

            cin>>a>>b>>c;

            if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b)

            cout<<"Right angled tringale\n";

            else

            cout<<"Not Right angled Triangle\n";

            return 0;

}

 

Output

The code given above when execute lead us towards the following results.

 

 

 

 

 

Note: Please note that this code is executable on Dev C++ IDE. If You have any other compiler than this code may cause issues. So it is advised to you that download and install the Dev C++ IDE for this code and if you can modify this code than well enough.

 

 

Thanks to take help from this site. I hope you have finds it understandable. If you have any query or any error in the code please inform us using the comment box or contact us page. Our team of experts will soon find a solution for you.


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents