1.

Write a program to check whether a string is palindrome or not. 

Answer»

A string is said to be palindrome if it is the same as the string constituted by reversing the characters of the original string. 

eg: “MALAYALAM”, “MADAM”, “ARORA”, “DAD”, etc

#include<iostream> 

using namespace std;

int main() 

{

char str[40]; 

int len,i,j; 

cout<<“Enter a string:”; 

cin>>str;

for(len=0;str[len]!-\0′;len++); 

for(i=0,j=len-1;<ilen/2;i++,j–)

if(str[i]!=str[j]) 

break; 

if(i==len/2) . 

cout<<str<<” is palindrome”;

else

cout<<str<<” is not palindrome”; 

}



Discussion

No Comment Found

Related InterviewSolutions