I am taking a 1000 random integers and putting them in an array of 1000. Then I am copying the array to another to sort them least to greatest so I can do I binary sort. Then with the other array I am doing a squential sort. The user is typing in a number to search the array for. Then we have to print the number searched, where in the array it was found, and how many times scanned.

Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int BIN_NUM, SEQ_NUM; int arraycpy(int *ia, int *ib); int compare (void *a, void *b); /* function prototype */ int bin_search (int *data, int n, int key); int seq_search(int *data, int n, int key); int arraycpy(int *ia, int *ib) { int x; x=0; while((ib[x]=ia[x])!='\0') { x++; } } int main() { int x, y, z, ia[1000], ib[1000], key; srand(time(NULL)); /* seed random # generator */ for(x=0; x<1000; x++) { /* select 50 numbers */ y=rand()%1000+1; /* generate random numbers from 1-1000 */ ia[x]=y; } printf("\nEnter an integer to search the array or -1 to quit:\n"); scanf("%d", &key); while(key!=-1) { qsort(ia, 1000, sizeof(int), compare); z=bin_search(key); printf("%d", z); return 0; } } int compare(void *a, void *b) { /* function to sort array */ return *(int*)a-*(int*)b; } int bin_search (int *data, int n, int key) { int found, midpoint, first, last, BIN_NUM; found = 0; first = 0; BIN_NUM = 0; last = n - 1; while ( ( first <= last ) && ! found ) { midpoint = (first + last) / 2; if ( data[midpoint] == key ) found = 1; else if ( data[midpoint] > key ) last = midpoint - 1; else first = midpoint + 1; BIN_NUM++; } if ( found ) return (midpoint); else return (-1); } int seq_search(int *data, int n, int key) { int found, i, SEQ_NUM; i = 0; found = 0; SEQ_NUM = 0; while ( ! found && ( i < n ) ) { if ( data[i] == key ) found = 1; else i++; SEQ_NUM++; } if ( found ) return (i); else return (-1); }