added strings topic
parent
33237f7d84
commit
29edbed58b
|
@ -0,0 +1,30 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// A function to check if a string str is palindrome
|
||||
void isPalindrome(char str[])
|
||||
{
|
||||
// Start from leftmost and rightmost corners of str
|
||||
int l = 0;
|
||||
int h = strlen(str) - 1;
|
||||
|
||||
// Keep comparing characters while they are same
|
||||
while (h > l)
|
||||
{
|
||||
if (str[l++] != str[h--])
|
||||
{
|
||||
printf("%s is Not Palindrome", str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("%s is palindrome", str);
|
||||
}
|
||||
|
||||
// Driver program to test above function
|
||||
int main()
|
||||
{
|
||||
isPalindrome("abba");
|
||||
isPalindrome("abbccbba");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue