164k views
3 votes
In this lab, you complete a prewritten c++ program that computes the largest and smallest of three integer values.

1 Answer

3 votes

Answer:

#include <iostream>

using namespace std;

int main() {

int num1, num2, num3;

int largest, smallest;

cout << "Enter three integers: ";

cin >> num1 >> num2 >> num3;

// Write your code here

cout << "The largest number is " << largest << endl;

cout << "The smallest number is " << smallest << endl;

return 0;

}

The code to complete the program is as follows:

//Write your code here

if (num1 >= num2 && num1 >= num3) {

largest = num1;

if (num2 >= num3) {

smallest = num3;

}

else {

smallest = num2;

}

}

else if (num2 >= num1 && num2 >= num3) {

largest = num2;

if (num1 >= num3) {

smallest = num3;

}

else {

smallest = num1;

}

}

else {

largest = num3;

if (num1 >= num2) {

smallest = num2;

}

else {

smallest = num1;

}

}

User Hessam
by
6.9k points