Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Given an integer array of length 100. There are no more than 20 data stored in it, arranged in ascending order, and all the other elements are 0. Requirements are as follows
Given an integer array of length 100. There are no more than 20 data stored in it, arranged in ascending order, and all the other elements are 0. Requirements are as follows
# Contains? & ltstdio.h & gt

# Definition? n? 100

//Select sorting function

Invalid? select_sort(int? *arr,int? n)

{

int? I,j,k,tmp

for(I = 0; I<n-1; i++)

{

k = I;

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

if(arr[k]& gt; arr[j])

k = j;

If (k! =i)

{

tmp = arr[I];

arr[I]= arr[k];

arr[k]= tmp;

}

}

}

//Insert a number num

Invalid? insertNum(int? *arr,? int? Ryan. int? n)

{

int? Me;

for(I = len- 1; ? Me? & gt=? 0; ? I-)

{

if(arr[I]& gt; n)?

arr[I+ 1]= arr[I];

Or what?

Break;

}

arr[I+ 1]= n;

}

int? Master ()

{

int? a[N]= { 0 }; ? //Initialize the array to 0

int? I,len,n;

scanf("%d ",& amplen); ? //Enter the length of the array

for(I = 0; I & ltleni++)

scanf("%d ",& ampa[I]); ? //Enter array elements

select_sort(a,len); //Call sorting function

scanf("%d ",& ampn); //Enter the element to insert.

insertNum(a,len,n); //Call the insert function

for(I = 0; I< len+1; I++)// Output new array elements.

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

Return? 0;

} Example of running results:

5 ? //Number of array elements to be entered

1 4 6 3 8 // Enter array elements.

5 // Element to be inserted

1 3 4 5 6 8 ? //Output the inserted array in ascending order.