Skip to content

Commit 0f59d51

Browse files
authored
Merge pull request #333 from Ravindu007/palindrome_in_c
palindrome_C
2 parents ccab7fa + 0510d92 commit 0f59d51

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Coding/C/palindrome.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int isPalindrome(char str[]) {
5+
int left = 0;
6+
int right = strlen(str) - 1;
7+
8+
while (left < right) {
9+
if (str[left] != str[right]) {
10+
return 0; // Not a palindrome
11+
}
12+
left++;
13+
right--;
14+
}
15+
16+
return 1; // It's a palindrome
17+
}
18+
19+
int main() {
20+
char str[100];
21+
22+
printf("Enter a string: ");
23+
scanf("%s", str);
24+
25+
if (isPalindrome(str)) {
26+
printf("'%s' is a palindrome.\n", str);
27+
} else {
28+
printf("'%s' is not a palindrome.\n", str);
29+
}
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)