Answer to Question #341395 in C++ for Nia

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.

1
Expert's answer
2022-05-17T08:56:51-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS