Question #341395

Write a program that reads in five integers and determines and prints the largest and


the smallest integers in the group. Use only the programming techniques you learned


up to now.

Expert's answer

#include <iostream>

using namespace std;

int main()
{
    int y, min, max;
    int count = 1;

    cout << "Enter an integer: ";
    cin >> y;
    
    min = y;
    max = y;

    while( count < 5)
    {
        cout << "Enter an integer: ";
        cin >> y;
    
        if(min > y)
        {
           min = y;
        }
        else if(max < y)
        {
           max = y;
        }
        ++count;
    }
        cout << endl;
        cout << "Smallest integer = "<< min << endl;
        cout << "Largest integer = " << max << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS