Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Use C language to define an integer array and write a program. The main function calls the following custom functions to complete. (1) Custom input
Use C language to define an integer array and write a program. The main function calls the following custom functions to complete. (1) Custom input

The code is as follows: #include?

#include?

#define?N?10

void?input(int?data[],?int?n)

{

int?i;

printf("Please enter % d integers: ",?n);

for?(i?=?0;?i?

scanf("%d ",?&data[i]);

}

}

void?sort(int?data[],?int?n)

{

int?i,?j,?temp;

for?(i?=?0;?i?

for?(j?=?0;?j?

if?( data[j]?

temp?=?data[j];

data[j]?=?data[ j?+?1];

data[j?+?1]?=?temp;

}

}

}

}

void?print(int?data[],?int?n)

{

int?i;

for?(i?=?0;?i?

printf("%d?",?data[i]);

}

printf("\n");

}

int?find(int?data[],?int ?n,?int?val)

{

int?i;

for?(i?=?0;?i?

if?(data[i]?==?val)?{

return?i;

}

}

return?-1;

}

//? Search in half

int?binary_find(int?data [],?int?n,?int?val){

int?low,?high,?mid;

low?=?0;

high?=?n?-?1;

while?(low?<=?high)?{

mid?=?(low?+?high)?/ ?2;

if?(data[mid]?==?val)

return?mid;

if?(data[mid]?> ?val)?{

low?=?mid?+?1;

}

if?(data[mid]?

high?=?mid?-?1;

}

}

return?-1;

}

int?main()

{

int?data[N],?val,?i;

input(data,?N);

sort(data,?N);

print(data,?N);

printf("Please Enter a number to be searched: ");

scanf("%d",?&val);

//?Search in half

i?= ?binary_find(data,?N,?val);

if?(i?!=?0)?{

printf("Number?%d? is in the data group The ?%d?th position. \n",?val,?i?+?1);

}

else?{

printf("Number?%d?in data Does not exist in the group.

\n",?val);

}

system("pause");

return?0;

}< /p>

Run results: