Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int poredi (const void *a, const void *b) {
- return *((int*)a) - *((int*)b);
- }
- int main () {
- int *a = NULL, b = NULL, n,i=0,x,k;
- scanf ("%i", &n);
- while (i<n) {
- a = realloc (a, (i+1) * sizeof(int));
- if (a == NULL)
- return -1;
- scanf ("%i", &k);
- a[i] = k;
- i++;
- }
- b = a;
- scanf ("%i", &x);
- int *rez = bsearch (&x, b, n, sizeof (int), poredi);
- if (rez == NULL)
- printf ("-1\n");
- else
- printf ("%i\n", rez-b);
- free (b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement