Skip to content

Commit ea27787

Browse files
authoredOct 1, 2020
Palindrome
C Program to Check if a Given String is Palindrome
1 parent c5c05c2 commit ea27787

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎palindrome

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
// A function to check if a string str is palindrome
5+
void isPalindrome(char str[])
6+
{
7+
// Start from leftmost and rightmost corners of str
8+
int l = 0;
9+
int h = strlen(str) - 1;
10+
11+
// Keep comparing characters while they are same
12+
while (h > l)
13+
{
14+
if (str[l++] != str[h--])
15+
{
16+
printf("%s is Not Palindrome", str);
17+
return;
18+
}
19+
}
20+
printf("%s is palindrome", str);
21+
}
22+
23+
// Driver program to test above function
24+
int main()
25+
{
26+
isPalindrome("abba");
27+
isPalindrome("abbccbba");
28+
isPalindrome("geeks");
29+
return 0;
30+
}

0 commit comments

Comments
 (0)
Please sign in to comment.