Created
December 2, 2017 19:49
-
-
Save jamby77/e0988f3be2fd5d67b999146b2c8d1b7a to your computer and use it in GitHub Desktop.
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
void minMax(int arr[],int size) { | |
int min, max, minIdx, maxIdx; | |
for (int i = 0; i < size; i++) | |
{ | |
if (i == 0) { | |
// при първото завъртане, слагаме стойността на мин и макс като стойността на | |
// първия елемент на масива и прескачаме на следващото завъртане | |
min = max = arr[i]; | |
minIdx = maxIdx = 0; | |
continue; | |
} | |
if (arr[i] < min) { | |
// ako elementa i e po-malyk ot min, go slagame za min | |
min = arr[i]; | |
minIdx = i; | |
} else if (arr[i] > max) | |
{ | |
// sytovetno ako e po-golqm ot max, go slagame za max | |
max = arr[i]; | |
maxIdx = i; | |
} | |
} | |
cout << "min: index = " << minIdx << " value = " << min << " max: index = " << maxIdx << " value = " << max << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment