[3303 views]
In this algorithm, first we declare an array of int a[100] to store array elements and the variable i and j to run the loop, n for getting the no. of elements in the array.
Res is for storing the result. We Read variable n and array a. We run for loop i=0 to i=n and inside that another loop for which will run from j=i to j=n.
We will check abs(a[i]-a[j]>res), it means that when we are subtracting a[0]-a[0] then a[0]-a[1] ,a[0]-a[2] ,a[0]-a[3]....a[0]-a[n].So we can see that when i=0 j will run from 0 to n then i=1 j will run from 1 to n. Likewise it will happen for all the numbers. So we are checking the subtraction of two elements and it's absolute value whether is greater than res or not. If it is greater it will get store in res otherwise it will pass.