Skip to content

Instantly share code, notes, and snippets.

@rocket-fuel86
Created February 18, 2026 14:46
Show Gist options
  • Select an option

  • Save rocket-fuel86/960ea9ae5fcc92c41864430bd3197677 to your computer and use it in GitHub Desktop.

Select an option

Save rocket-fuel86/960ea9ae5fcc92c41864430bd3197677 to your computer and use it in GitHub Desktop.
#include <iostream>
void calcMinMaxArray(int array[], const unsigned int LENGTH, int* max, int* min)
{
*max = array[0];
*min = array[0];
for (unsigned int i = 0; i < LENGTH; i++)
{
if (array[i] > *max)
{
*max = array[i];
}
if (array[i] < *min)
{
*min = array[i];
}
}
}
int main()
{
const unsigned int LENGTH = 3;
int array[] = { 10, 83, 47 };
int max = 0, min = 0;
calcMinMaxArray(array, LENGTH, &max, &min);
std::cout << max << ' ' << min << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment