Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to operate the "top three" minimum values in a set of numbers output by C language?
How to operate the "top three" minimum values in a set of numbers output by C language?
# include & ltstdio.h & gt

int main()

{ int i,j,k,t,n,a[ 100];

scanf("%d ",& ampn);

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

scanf("%d ",& ampa[I]);

for(I = 0; I<3; I++)// Only the first 3 rounds of sorting are selected.

{ k = I; //k is the position of the current minimum number.

for(j = I+ 1; j & ltn; J++)// scan every number after I.

if(a[j]& lt; a[k])k = j; //If the new number is less than the current minimum number, update the minimum number position.

t = a[I];

a[I]= a[k];

a[k]= t; //Switch the current minimum number to bit i..

}

printf("%d %d %d\n ",a[0],a[ 1],a[2]);

Returns 0;

}