Q-05: Write a function that checks whether a given string is palindrome or not.
    

Using - C


#include<stdio.h> #include<string.h> int checkPalindrome(char str[ ]); void main() { char str[1024]; printf("Enter a string: "); gets(str); if(checkPalindrome(str)) printf("It is a palindrome string!"); else printf("It is not a palindrome string!"); } int checkPalindrome(char str[ ]) { int length, i; length = strlen(str); for(i=0; i < length; i++) { if(str[i] != str[length-1-i]) { return 0; } } return 1; }

OUTPUT

Case-1:
---------------------------------
Enter a string:  hello World
It is not a palindrome string!

Case-2: --------------------------------- Enter a string: w o w It is a palindrome string!
        

Using - C++


#include<iostream> #include<string.h> using namespace std; int checkPalindrome(string str); int main() { string str; cout<< "Enter a string: "; getline(cin,str); if(checkPalindrome(str)) cout<< "It is a palindrome string!"; else cout<< "It is not a palindrome string!"; return 0; } int checkPalindrome(string str) { int length, i; length = str.length(); for(i=0; i < length; i++) { if(str[i] != str[length-1-i]) { return 0; } } return 1; }

OUTPUT

Case-1:
---------------------------------
Enter a string: momo
It is not a palindrome string!

Case-2: --------------------------------- Enter a string: radar It is a palindrome string!