(Sides of a Triangle) Write a program that reads three nonzero double values and determines and prints whether they could represent the sides of a triangle.
#include < iostream>
using namespace std;
int main()
{
double a, b, c;
cout << "Enter the three numbers: " << endl;
cin >> a >> b >> c;
if( (a + b <= c) | | (b + c <= a) | | (a + c <= b) )
cout << "They could NOT represent the sides of a triangle" << endl;
else
cout << "They could represent the sides of a triangle" << endl;
//for pause
system("PAUSE") ;
return 0;
}
Solution:
#include < iostream>
using namespace std;
int main()
{
double a, b, c;
cout << "Enter the three numbers: " << endl;
cin >> a >> b >> c;
if( (a + b <= c) | | (b + c <= a) | | (a + c <= b) )
cout << "They could NOT represent the sides of a triangle" << endl;
else
cout << "They could represent the sides of a triangle" << endl;
//for pause
system("PAUSE") ;
return 0;
}
Post A Comment:
0 comments: