Skip to content

Instantly share code, notes, and snippets.

@eduardoaugustojulio
Created March 16, 2021 18:10
Show Gist options
  • Save eduardoaugustojulio/18fbafdaf62a4f3d599dfe9e5b4c7f31 to your computer and use it in GitHub Desktop.
Save eduardoaugustojulio/18fbafdaf62a4f3d599dfe9e5b4c7f31 to your computer and use it in GitHub Desktop.
MaxDiff
#include <stdio.h>
#include <stdlib.h>
int maxDiff(int array[], int n)
{
int maxDiff = 0;
for(int i = 1; i < n; i++)
{
for(int j = 0; j < i; j++)
{
if(array[i] > array[j] && (array[i] - array[j] > maxDiff))
{
maxDiff = array[i] - array[j]
}
}
}
return maxDiff;
}
int main(const int argc, const char **argv)
{
int array[4] = {2, 3, 5, 4};
maxDiff(array, 4)
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment