-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome_checker.c
More file actions
50 lines (40 loc) · 867 Bytes
/
Palindrome_checker.c
File metadata and controls
50 lines (40 loc) · 867 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Check the symbols in index i and index j
*/
// int isPalindrome(char X[]) {
// int n = strlen(X)-1;
// for (int i=0; i <(n/2); i++){
// if (X[i]!= X[n-i]){
// return 0;
// }
// }
// return 1;
// }
int isPalindrome(char X[], int i , int j) {
if (i>j){
if(X[i]!=X[j]){
return 0;
}
isPalindrome(X, i+1, j-1);
}
return 1;
}
int main() {
char X[] = "1a_b3cD45t54Dc3b_a1";
// if (isPalindrome(X)==1) {
// printf("This is a Palindrome.");
// }
// else {
// printf("This is not a Palindrome.");
// }
if (isPalindrome(X, 0, strlen(X)-2)==1) {
printf("This is a Palindrome.");
}
else {
printf("This is not a Palindrome.");
}
return 0;
}