Inactive Tutor answered 03/08/22
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char **argv) {
double side1, side2;
cin >> side1;
cin >> side2;
printf("%0.2f\n", sqrt(side1*side1 + side2*side2));
return 0;
}
Brock T.
asked 03/08/22Concepts tested: Mathematical computation, formatting output
Write a program that:
1) Reads in the length of 2 sides of a triangle as double (do NOT print out any prompts/instructions for the user)
2) Computes the length of the 3rd side using the Pythagorean theorem (a^2 + b^2 = c^2, where a, b, and c, are the side lengths)
3) Presents the length of the 3rd side with exactly 2 digits after the decimal point
Example Input / Output:
2.3658
3.36954
4.12
Inactive Tutor answered 03/08/22
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char **argv) {
double side1, side2;
cin >> side1;
cin >> side2;
printf("%0.2f\n", sqrt(side1*side1 + side2*side2));
return 0;
}
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.