+ 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
5 Respuestas
+ 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.
+ 6
i can provide c++ or java code as well :))
+ 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;
}
0
thanks Buddy
0
please upvote my answer to your question