Submit three c++ files: 1. Write a program that prompts the user to input a numb
ID: 3906776 • Letter: S
Question
Submit three c++ files:
1. Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero.
********************************************************************************************************************************************
2. Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order.
********************************************************************************************************************************************
3. In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle.
Explanation / Answer
Code 1
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if(n>0)cout<<"The number is positive ";
else if(n<0)cout<<"The number is negative ";
else cout<<"The number is zero ";
}
Code 2
#include <iostream>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
{
if(c>b)cout<<b<<" "<<c<<" "<<a;
else cout<<c<<" "<<b<<" "<<a;
}
else cout<<b<<" "<<a<<" "<<c;
}
else
{
if(b>c)
{
if(c>a)cout<<a<<" "<<c<<" "<<b;
else cout<<c<<" "<<a<<" "<<b;
}
else cout<<a<<" "<<b<<" "<<c;
}
}
Code 3
#include <iostream>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
a*=a;b*=b;c*=c;
if(a+b==c || a==b+c || b==a+c)cout<<"Its a right angle triangle ";
else cout<<"Its not a right angle triangle ";
}
Do give a thumbs up