-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_the_odd_int_main.c
More file actions
38 lines (32 loc) · 1.17 KB
/
find_the_odd_int_main.c
File metadata and controls
38 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
6 kyu
Find the odd int
https://www.codewars.com/kata/54da5a58ea159efa38000836
*/
#include <stdio.h>
#define ARR_LEN(array) (sizeof(array) / sizeof *(array))
#define fixed_test(expected, array) do_test(ARR_LEN(array), array, expected)
int find_odd(size_t length, const int array[length]);
static void print_array(size_t length, const int array[length]) {
printf("{");
for (size_t i = 0; i < length; i++)
printf("%d%s", array[i], (i == length - 1) ? "" : ", ");
printf("}");
}
static void do_test(size_t length, const int array[length], int expected) {
int actual = find_odd(length, array);
printf("For array = ");
print_array(length, array);
printf(" expected %d, but got %d. %s\n", expected, actual,
(expected == actual) ? "OK." : "WRONG.");
}
int main(void) {
fixed_test(
5, ((int[]){20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5}));
fixed_test(-1, ((int[]){1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5}));
fixed_test(5, ((int[]){20, 1, 1, 2, 2, 3, 3, 5, 5, 4, 20, 4, 5}));
fixed_test(10, ((int[]){10}));
fixed_test(10, ((int[]){1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1}));
fixed_test(1, ((int[]){5, 4, 3, 2, 1, 5, 4, 3, 2, 10, 10}));
return 0;
}