Current location - Trademark Inquiry Complete Network - Futures platform - Sort 10 integers by selection method. The integer 10 is input by the scanf function.
Sort 10 integers by selection method. The integer 10 is input by the scanf function.
# Contains &; stdio.h & ampgt;

void main()

{

int i,j,min,temp,a[ 1 1];

Printf ("input data; \ n ");

for(I = 1; I & = 10; i++)

{printf("a[%d]= ",I);

scanf("%d ",& ampa & amplt; I > );

}

printf(" \ n ");

Printf ("original number: \ n");

for(I = 1; I & = 10; i++)

printf("%5d ",a & amplt; I > );

printf(" \ n ");

for(I = 1; I & =9; i++)

{ min = I;

for(j = I+ 1; Johnson & Johnson company lt; = 10; j++)

if(a[min]& amp; gt; a[j])min = j;

temp = a & amplt; I > ;

a & amplt; I > = a[min];

a[min]= temp;

}

Printf ("\ nSorted number; \ n ");

for(I = 1; I & = 10; i++)

printf("%5d ",a & amplt; I > );

printf(" \ n ");

}

Extended data:

The function of scanf can be summarized in one sentence: "Assign values to variables in the program through the keyboard". The prototype of this function is:

# Contains &; stdio.h & ampgt;

Int scanf(const char * format, ...);

Its usage, or there are two formats.

Scanf ("input controller", input parameters);

Function: Convert the characters input by the keyboard into data in the specified format in the input control symbol, and then store it in a variable with the value of the input parameter as the address.

Example:

# Contains &; stdio.h & ampgt;

int main(void)

{

int I;

I = 10;

printf("i=%d\n ",I);

Returns 0;

}

References:

Baidu encyclopedia -SCANF (computer language function)