109k views
0 votes
Write a program that asks the user to enter five different, integer numbers. The program then reports the largest number and the smallest number.

1 Answer

2 votes

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int mi=INT_MAX;

int mx=INT_MIN;

int Num;

cout<<"enter five different Numbers:";

// read 10 non-negative Numbers

for(int a=1;a<=5;a++)

{

// read the input number

cin>>Num;

// find maximum

if(Num>mx)

{

mx=Num;

}

// find minumum

if(Num<mi)

{

mi=Num;

}

}

// print maximum and minimum

cout<<"maximum of five numbers is: "<<mx<<endl;

cout<<"minimum of five numbers is: "<<mi<<endl;

return 0;

}

Step-by-step explanation:

Declare two variables "mi" & "mx" and initialize them with INT_MAX and INT_MIN respectively.Then read the five number from user and compare it with "mi" & "mx" ,if input is greater than "mx" then update "mx" or if input is less than "mi" then update the "mi". After all the inputs, "mi" will have smallest and "mx" will have largest value.

Output:

enter five different Numbers:6 19 3 44 23

maximum of five numbers is: 44

minimum of five numbers is: 3

User Serey
by
9.1k points