In a given array find the min and max distance between any two numbers.
Example:
Input: (3, 6, 9, 2)
Output: 1, 7
Algorithms
1) sort the array.
2) for min subtract index no. zero elemenet to index 1 element
3) for max subtract last element to index zero element in array
All Source code given below
#include
int main(){
int arr[10],n,temp;
int max,min;
printf("Enter the size of Array: ");
scanf("%d",&n);
printf("Enter the Element in Array: ");
for(int i=0; iarr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
min=arr[1]-arr[0];
max=arr[n-1]-arr[0];
printf("%d,%d",max,min);
return 0;}