+ 3

How we can find maximum and minimum numbers

#include<iostream> using namespace std; int main() { int a,b,c,d,e; cout<<"Enter numbers"<<endl; cin>>a; cin>>b; cin>>c; cin>>d; cin>>e; //*find max and min numbers if(a>b && a>c && a>d && a>e) { cout<<"Max is "<<a; } else if (b>a && b>c && b>d && b>e) { cout<<"Max is "<<b; } else if(c>b && c>a && c>d && c>e) { cout<<"Max is "<<c; } else if(d>b && d>c && d>a && d>e) { cout<<"Max is "<<d; } els

10th Nov 2016, 6:27 PM
Ahmad Ali
Ahmad Ali - avatar
5 ответов
+ 6
if you have an array of numbers, you can create a variable min or max which will be equal to the first element of the array. Then with for loop, you can go through your array from the second number, and compare each number of the array with min or max, if any of them is less or greater than min or max, it should become min or max.
10th Nov 2016, 6:32 PM
LyannaM
LyannaM - avatar
+ 6
i can provide c++ or java code as well :))
10th Nov 2016, 6:33 PM
LyannaM
LyannaM - avatar
+ 5
#include <iostream> using namespace std; int main() { int input; int max = 0; int min = 0; cout << "Enter number: "; while (input != -1) { cin >> input; if(input != -1) { if(input > max) { max = input; } if(input < min) { min = input; } } } cout <<"Max: " << max << " Min " << min << endl; }
10th Nov 2016, 6:30 PM
Reza PourMohammadHosein Niaky
Reza PourMohammadHosein Niaky - avatar
0
thanks Buddy
10th Nov 2016, 6:33 PM
Ahmad Ali
Ahmad Ali - avatar
0
please upvote my answer to your question
10th Nov 2016, 6:39 PM
Reza PourMohammadHosein Niaky
Reza PourMohammadHosein Niaky - avatar