Created
March 16, 2021 18:10
-
-
Save eduardoaugustojulio/18fbafdaf62a4f3d599dfe9e5b4c7f31 to your computer and use it in GitHub Desktop.
MaxDiff
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 <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