Answer to Question #343340 in C++ for menna

Question #343340

Write a C++ program that inputs three integers from the user and prints the smallest and largest of these numbers.


1
Expert's answer
2022-05-22T18:10:11-0400
#include <iostream>
using namespace std;


int main()
{
    int numbers[3];
    cout<<"Enter 3 integers:";
    for(int i =0;i<3;i++){
        cin>>numbers[i];
    }
    
    int smallest = numbers[0];
    int biggest = numbers[0];
    
    for(int i=0;i<3;i++){
        if(numbers[i]<smallest) smallest=numbers[i];
        if(numbers[i]>biggest) biggest=numbers[i];
    }
    
    cout<<"The biggest:"<<biggest<<endl;
    cout<<"The smallest:"<<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