Skip to content

Instantly share code, notes, and snippets.

@Darkborderman
Created May 7, 2018 06:34
Show Gist options
  • Save Darkborderman/130e24621e8e363aaf3d9dde78952a83 to your computer and use it in GitHub Desktop.
Save Darkborderman/130e24621e8e363aaf3d9dde78952a83 to your computer and use it in GitHub Desktop.
A algorithm to find minium and maxium in an array.
#include<iostream>
using namespace std;
class min_max
{
public:
min_max(int min,int max)
{
this->min=min;
this->max=max;
}
int min;
int max;
};
int main()
{
int input[15]={1,5,72,6,41,32,8,9,7,4,51,3,6,7,412};
int length=15;
min_max output(input[0],input[0]);
for(int i=0;i<=length-1;i++)
{
if(input[i]>output.max) output.max=input[i];
if(input[i]<output.min) output.min=input[i];
}
cout<<output.min<<" "<<output.max;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment