-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpalindrome.c
More file actions
32 lines (26 loc) · 746 Bytes
/
palindrome.c
File metadata and controls
32 lines (26 loc) · 746 Bytes
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
#include <stdbool.h>
#include <assert.h>
bool is_palindrome(char *str, int index, int size)
{
if (index > size / 2) {
return true;
}
if (str[index] != str[size - index]) {
return false;
}
return is_palindrome(str, index + 1, size);
}
int main()
{
assert(!is_palindrome("ankit", 0, 4));
assert(!is_palindrome("lirxil", 0, 5));
assert(!is_palindrome("kaayak", 0, 5));
assert(!is_palindrome("ka ya k", 0, 6));
assert(!is_palindrome("namasman", 0, 7));
assert(is_palindrome("liril", 0, 4));
assert(is_palindrome("kayak", 0, 4));
assert(is_palindrome("racecar", 0, 6));
assert(is_palindrome("rotator", 0, 6));
assert(is_palindrome("rottaattor", 0, 9));
return 0;
}