Skip to content

Commit 58f1cef

Browse files
authored
Merge pull request #595 from AnupKumarGupta/Is_Palindrome_in_C
Adds Palindrome program in C
2 parents e8b0423 + a7a59bd commit 58f1cef

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

palindrome/palindrome.c

Lines changed: 30 additions & 0 deletions
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 Palindromen", str);
17+
return;
18+
}
19+
}
20+
printf("%s is palindromen", str);
21+
}
22+
23+
// Driver program to test above function
24+
int main()
25+
{
26+
char str[100];
27+
scanf("%s",str);
28+
isPalindrome(str);
29+
return 0;
30+
}

0 commit comments

Comments
 (0)