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;
}
LATEST TUTORIALS
APPROVED BY CLIENTS