+ 1
what is wrong in this code?? Trying to find max and min integer in an array.
#include<iostream> using namespace std; int getMin(int num[], int n){ int min = INT_MAX; for (int i = 0; i < n; i++) { if (num[i]<min) { min=num[i]; } } return min; } int getMax(int num[], int n){ int max = INT_Min; for (int i = 0; i < n; i++) { if (num[i]>max) { max=num[i]; } } return max; } int main(){ int size; cin>>size; int num[100]; for (int i = 0; i < size; i++) { cin>>num[i]; } cout<<"Max Value"<<getMax(num, size)<<endl; cout<<"Min Value"<<getMin(num, size)<<endl; }
2 odpowiedzi
+ 1
Add header file climits and inside getMax function where you can written INT_Min it should be capital MIN
0
//what is wrong in this code?? Trying to find max and min integer in an array.
#include<iostream>
#include<climits>
using namespace std;
int getMin(int num[], int n){
int min = INT_MAX;
for (int i = 0; i < n; i++)
{
if (num[i]<min)
{
min=num[i];
}
}
return min;
}
int getMax(int num[], int n){
int max = INT_MIN;
for (int i = 0; i < n; i++)
{
if (num[i]>max)
{
max=num[i];
}
}
return max;
}
int main(){
int size;
cin>>size;
int num[100];
for (int i = 0; i < size; i++)
{
cin>>num[i];
}
cout<<"Max Value"<<getMax(num, size)<<endl;
cout<<"Min Value"<<getMin(num, size)<<endl;
}