A program to input a number and check whether it is a palindrome or not.

 

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
int i,j,mid,length;
char a[100];
i=0;
j=0;
cout<<"Enter the string:";
gets(a);
length= strlen(a);
mid=length/2;
length=length-1;
while(i!=mid)
{
if(a[i]!=a[length])
{
cout<<"The string is not a palindrome.";
j=1;
break;
}
else
i++;
length--;
}
if(j==0)
cout<<"The string is a palindrome.";
getch();
}

 

< Back