-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Thursday 9 July 2015

Basic theorem of triangle

Now it is time to use C++ in our daily life.As a Mathematics student,you have read that the sum of two sides of a triangle is greater than the third side. 

So,today I am here with an interesting program that will input 3 numbers from the user and it will determine whether these sides form a triangle or not.

Below is the source code of this program.

Source code

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter the value of A:";
cin>>a;
cout<<"Enter the value of B:";
cin>>b;
cout<<"Enter the value of C:";
cin>>c;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"The sides form a triangle."<<endl;
}
else
{
cout<<"The sides do not form a triangle."<<endl;
}
return 0;
}

Output

property of triangle

Explanation

As the user has entered A=10,B=20,C=30. So, 

A+B>C:10+20>30.

The condition becomes false in the start and it will go into the "else" condition and will display, "The sides do not form a triangle.

No comments:

Post a Comment