Created
May 7, 2018 06:34
-
-
Save Darkborderman/130e24621e8e363aaf3d9dde78952a83 to your computer and use it in GitHub Desktop.
A algorithm to find minium and maxium in an array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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