In this lab, you complete a prewritten C++ program that computes the largest and smallest of three integer values. Instructions Two variables named largest and smallest are declared for you. Use these variables to store the largest and smallest of the three integer values. You must decide what other variables you will need and initialize them if appropriate. Your program should prompt the user to enter 3 integers. Write the rest of the program using assignment statements, if statements, or if else statements as appropriate. There are comments in the code that tell you where you should write your statements. The output statements are written for you. Execute the program by clicking the Run button at the bottom of the screen. Using the input of -50, 53, 78, your output should be: The largest value is 78 The smallest value is -50

Respuesta :

Answer:

The program in C++ is as follows

#include <iostream>

using namespace std;

int main(){

   int n1, n2, n3, largest, smallest;

   cin>>n1>>n2>>n3;

   if(n1 >= n2 && n1>=n3){        largest = n1;    }

   else if(n2 >= n1 && n2>=n3){        largest = n2;    }

   else{        largest = n3;    }

   if(n1 <= n2 && n1<=n3){        smallest = n1;    }

   else if(n2 <= n1 && n2<=n3){        smallest = n2;    }

   else{        largest = n3;    }

   cout<<"Smallest: "<<smallest<<endl;

   cout<<"Largest: "<<largest<<endl;

   return 0;

}

Explanation:

Declare all variables

   int n1, n2, n3, largest, smallest;

Get input for the three numbers

   cin>>n1>>n2>>n3;

Check if n1 is the largest

   if(n1 >= n2 && n1>=n3){        largest = n1;    }

Check if n2 is the largest

   else if(n2 >= n1 && n2>=n3){        largest = n2;    }

Otherwise, n3 is the largest

   else{        largest = n3;    }

Check if n1 is the smallest

   if(n1 <= n2 && n1<=n3){        smallest = n1;    }

Check if n2 is the smallest

   else if(n2 <= n1 && n2<=n3){        smallest = n2;    }

Otherwise, n3 is the smallest

  else{        largest = n3;    }

Print the smallest

   cout<<"Smallest: "<<smallest<<endl;

Print the largest

   cout<<"Largest: "<<largest<<endl;