I am posting my program below but it finds the maximum numbe

I am posting my program below but it finds the maximum number. How can I change it to find minimum number? I need the same program. Thank you.

Solution

Hi,

I have updated the code and highlighted the code changes below.

#include<iostream>
using namespace std;
// find largest of any number of integers
int MAXIMUM(int [], int );
int MINIMUM(int [], int );
int main()
{
int k =0, max =0, Largest = 0, Smallest = 0;
cout<<\"how many numbers ?\"<<\"\ \";
cin>>k;
int num[k];
for(int i=0; i<k; i++)
{
cout<<\"enter number\"<<endl;
cin>>num[i];
}
Largest = MAXIMUM(num, k);
cout<<\"largest number \"<<Largest<<endl;
  
Smallest = MINIMUM(num, k);
cout<<\"smallest number \"<<Smallest<<endl;

system(\"pause\");
return 0;
}


int MAXIMUM( int n[], int k )
{
int max = 0;
for(int j = 0; j<k; j++)
{
if(n[j]>max)
max = n[j];
}
return max;
}
int MINIMUM( int n[], int k )
{
int min = n[0];
for(int j = 0; j<k; j++)
{
if(n[j]<min)
min = n[j];
}
return min;
}

Output:

sh-4.3$ main                                                                                                                                                                                                                

how many numbers ?                                                                                                                                                                                                          

5                                                                                                                                                                                                                           

enter number                                                                                                                                                                                                                

3                                                                                                                                                                                                                           

enter number                                                                                                                                                                                                                

2                                                                                                                                                                                                                           

enter number                                                                                                                                                                                                                

1                                                                                                                                                                                                                           

enter number                                                                                                                                                                                                                

4                                                                                                                                                                                                                           

enter number                                                                                                                                                                                                                

5                                                                                                                                                                                                                           

largest number   5                                                                                                                                                                                                          

smallest number   1

I am posting my program below but it finds the maximum number. How can I change it to find minimum number? I need the same program. Thank you.SolutionHi, I have
I am posting my program below but it finds the maximum number. How can I change it to find minimum number? I need the same program. Thank you.SolutionHi, I have

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site