Answer to Question #269986 in C++ for Glady_07

Question #269986

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-22T09:53:38-0500


SOLUTION CODE




#include <iostream>
using namespace std;


int main() {
	
	int positive_integers[5];
	
	for(int i = 0; i< 5; i++)
	{
		cout<<"Enter positive integer "<<(i+1)<<": ";
		int my_positive_integer;
		cin>>my_positive_integer;
		positive_integers[i]=my_positive_integer;
		
	}
	int largest = positive_integers[0];
	int smallest = positive_integers[0];
    for(int i = 0; i<5; i++)
    {
    	if(positive_integers[i]>largest)
    	{
    		largest = positive_integers[i];
		}
		
		if(positive_integers[i]<smallest)
    	{
    		smallest = positive_integers[i];
		}
	}


    cout<<"\nThe largest number entered by the user is "<<largest<<endl;
    cout<<"\nThe smallest number entered by the user is "<<smallest<<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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS