Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C Language Question: Given an integer array, find the minimum difference between two numbers.
C Language Question: Given an integer array, find the minimum difference between two numbers.
# contains "stdio.h"

# Define N 5

int main(int argc,char *argv[]){

int a[N]={ 1,3,4, 1 1,8},I,j,k,t;

for(I = 0; I & ltn;; i++)

for(j = I+ 1; j & ltn; j++){

If (t=a[i]-a[j], t<0)

t =-t;

if(k & gt; t || i==0)

k = t;

}

Printf ("Result is %d\n", k);

Returns 0;

}

Extended data:

The elements in the array are stored in order, and they are stored together in memory in this order. All elements in the array have the same data type.

Array elements are represented by the name of the whole array and its sequential position in the array. For example, a[0] represents the first element in an array named A, a[ 1] represents the second element of array A, and so on. The elements in the array are stored in consecutive memory blocks and accessed through indexes.