lang-bootstrap/05/main.c

34 lines
742 B
C
Raw Normal View History

2022-02-14 22:43:25 -05:00
#define _STDLIB_DEBUG
2022-02-15 22:41:18 -05:00
#include <math.h>
#include <stdio.h>
2022-02-16 12:25:14 -05:00
#include <signal.h>
2022-02-16 15:41:30 -05:00
#include <stdlib.h>
int compar(const void *a, const void *b) {
int i = *(int *)a;
int j = *(int *)b;
if (i < j) return -1;
if (i > j) return 1;
return 0;
}
2022-02-16 12:25:14 -05:00
2022-02-15 16:36:52 -05:00
int main(int argc, char **argv) {
2022-02-16 15:41:30 -05:00
ldiv_t l = ldiv(1000000000007, 5937448);
printf("%ld %ld\n",l.quot,l.rem);
int nums[10] = {8,34,1086,3872,-123,5873,3843,1762,INT_MAX,INT_MIN};
int i;
for (i = 0; i < 10; ++i) nums[i] = abs(nums[i]);
qsort(nums, 10, sizeof(int), compar);
for (i = 0; i < 10; ++i) printf("%d ", nums[i]);
printf("\n");
int search = 34;
int *p = bsearch(&search, nums, 10, sizeof(int), compar);
if (p)
printf("Found %d\n",*p);
else
printf("No match\n");
return 0;
2022-02-09 22:44:27 -05:00
}
2022-02-12 21:27:57 -05:00