How to write a Program to check if a string is palindrome in C++ Programming ?
C++ Program to check if a string is palindrome. |
Solution:
//Program to check if a string is palindrome.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char a[80];
int z=1;
cout<<"Enter a string: ";
gets(a);
int n=strlen(a);
for(int i=0,j=n-1;i<=(n-1)/2;i++,j--)
{
if(a[i]!=a[j])
{
z=0;
break;
}
}
if(z==0)
cout<<"The string is not palindrome.";
else
cout<<"The string is palinrome.";
getch();
}
This C++ Program to check if a string is palindrome.