The specific requirements for the job are as follows:
Write a complete program that implements the following functions.
(1) Enter 10 unordered integers.
(2) The 10 unordered integers received above are sorted in order from large to small by using the selection sort method.
(3) Require any input an integer, using the binary lookup method to find the number in the order of 10 numbers, if present, in the main function to output its location, otherwise, the hint is not found.
Hint: the input function can be defined to complete 10 integers, the sort function completes the input number, the search function
Complete the search function for the number of inputs.
Here is the specific code: (I lazy, did not write comments, but carefully read the code, or very simple)
1#include <stdio.h>2 #defineN 103 4 //3 -From5 6 int*input ();7 int*sort (intm[]);8 voidSearchintM[],intc);9 Main ()Ten { One int*A; A inti,k; - intM[n]; -A=input (); the for(i=0; i<n;i++) - { -m[i]=*A; -a++; + } -A=sort (m); +printf"\ n Sort results: \ n"); A for(i=0; i<n;i++) at { -m[i]=*A; -a++; -printf"%d\n", M[i]); - } - in for(i=0;i< -; i++) -{printf ("Please enter the number you want to find:"); toscanf"%d",&k); + search (m,k); - } the * } $ voidSearchintM[],intc)Panax Notoginseng { - inth,l,i; the for(h=0, l=n;h<=l;) + { AI= (h+l)/2; the if(c==M[i]) + { -printf"is the first%d element \ n", i+1); Break; $ } $ Else if(c>M[i]) -l=i-1; - Else if(c<M[i]) theh=i+1; - }Wuyi if(h>l) theprintf"no This element"); - return 0; Wu } - int*sort (intm[]) About { $ inti,j; - intindex,temp; - for(i =0; I < N-1; i++) - { Atemp =0; +index =i; the for(j = i +1; J < N; J + +) - { $ if(M[index] <M[j]) the { theindex =J; the } the } -temp =M[index]; inM[index] =M[i]; theM[i] =temp; the } About returnm; the } the int*input () the { +printf"Please enter a 10 integer: \ n"); - Static intM[n]; the inti;Bayi for(i=0; i<n;i++) the { thescanf"%d",&m[i]); - } - returnm; the}
The implementation function of the C language returns an array, as well as a selection sort, and a binary lookup. This is a student's homework ...