Question

Convert your algorithm into a C++ program. Your program should output the value of the longest...

Convert your algorithm into a C++ program. Your program should output the value of the longest side of the right-angled triangle.

Note, to answer the question, you will need to be able to do square root. To do square root, follow these 2 steps.

1) include the cmath library that allows square root using the statement

#include <cmath>

2) To perform a square root, use the syntax

sqrt(a double variable or number goes in here);

For example

cout << sqrt(25.0);   

OR

double answer = sqrt(25.0);

The first statement above will display 5 to the output screen and the second statement will store the 5 in a variable. Use whichever you like

Homework Answers

Answer #1

C++ code:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    //initializing two sides
    double side1,side2;
    //asking for their lengths
    cout<<"Enter the lengths of the other two sides: ";
    //accepting them
    cin>>side1>>side2;
    //printing the length of longest side by finding square root of both sides squared and added
    cout<<"The length of the longest side is "<<sqrt(side1*side1+side2*side2)<<endl;
    return 0;
}

Screenshot:


Input and Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's length, width, and area Define an overloaded constructor and use it when creating the Rectangle object instead of using the setters. Change this program to calculate and display the rectangle's perimeter. Example: In feet, how wide is your house? 20 In feet, how long is your house? 25 The house is 20.00 feet wide. The house is 25.00 feet long. The house has 500.00...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...