Answer to Question #271013 in C++ for Gladymer Gonzaga

Question #271013

Array

Create a program that will ask a user to enter 5 positive numbers.

The program will then display the largest and the smallest value that was entered by the user.


1
Expert's answer
2021-11-24T14:09:35-0500
#include <iostream>
using namespace std;
int main()
{
    int arr[5];
    int minNum,maxNum;
    cout<<"Enter 5 positive numbers: ";
    for(int i=0;i<5;++i) cin>>arr[i];
    minNum=arr[0];
    maxNum=arr[0];
    for(int i=1;i<5;++i)
    {
        if (minNum<arr[i]) minNum=arr[i];
        if (maxNum>arr[i]) maxNum=arr[i];
    }
    cout<<"Largest value: "<<maxNum<<endl;
    cout<<"Smallest value: "<<minNum<<endl;
    return 0;
}

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

Gladymer Gonzaga
27.11.21, 08:48

Thank you so much

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS