Last active
December 9, 2017 08:17
-
-
Save harshityadav95/69374e91b80b0e40644268938376240d to your computer and use it in GitHub Desktop.
Differnce between the smallest and largest element in the array
This file contains hidden or 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
int maxDiff(int arr[]) | |
{ | |
int arr_size = arr.length; | |
int max_diff = arr[1] - arr[0]; | |
int i, j; | |
for (i = 0; i < arr_size; i++) | |
{ | |
for (j = i + 1; j < arr_size; j++) | |
{ | |
if (arr[j] - arr[i] > max_diff) | |
max_diff = arr[j] - arr[i]; | |
} | |
} | |
return max_diff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment