We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ccab7fa + 0510d92 commit 0f59d51Copy full SHA for 0f59d51
Coding/C/palindrome.c
@@ -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