I have a lab due that I don\'t understand how to write. I\'m new to programming
ID: 3537536 • Letter: I
Question
I have a lab due that I don't understand how to write. I'm new to programming and my online teacher is no help. Heres the questions I don't understand how do I proram this using VC++.
Write a complete program to solve the following problem.
Prompt the user for the length of the 3 sides of a triangle in ascending order.
If a, b, and c represent the 3 sides of a triangle, the last value input will be c, the
longest side.
The following calculations can be made:
1. perimeter = a + b + c
2. Set s = 0.5(a + b + c)
the area of the triangle is the square root
of s(s %u2013 a)(s %u2013b)(s-c)
3. The triangle will be a right triangle, i.e. have a 90 degree angle,
if c squared %u2013 the sum of a squared and b squared is equal to 0
Output to the screen the 3 sides, the perimeter, the area, and if the triangle is a
right triangle or not.
You will need to use the sqrt function, so you will need to include <cmath>
Run the program twice using the following data
3.0 4.0 5.0
5.0 6.0 7.0
Explanation / Answer
please rate = thanks
any questions just ask
#include <iostream>
#include <cmath>
using namespace std;
int main()
{ double a,b,c,area,perimeter,s;
cout<<"Enter the sides of a triangle in ascending order ";
cout<<"Enter side 1: ";
cin>>a;
cout<<"Enter side 2: ";
cin>>b;
cout<<"Enter side 3: ";
cin>>c;
perimeter=a+b+c;
s=perimeter/2.;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"sides: "<<a<<", "<<b<<" and "<<c<<" ";
cout<<"area: "<<area<<" square units"<<endl;
cout<<"perimeter: "<<perimeter<<endl;
if(a*a+b*b==c*c)
cout<<"This is a right triangle ";
else
cout<<"This is not a right triangle ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.