Tuesday, 13 September 2016

Palindrome

C++ Programs


A Palindrome is a number that can be read in both ways (left to right and right to left) and still the value remains the same.
For example: 121 , 1234321 ,  56665 , 6776 etc.

The following program asks the user to enter a 3-digit number, and outputs whether the number entered is a palindrome or not.

In this I have used if-else statements.

Code:

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter a 3 digit number: ";
cin>>a;

b=a%10;
c=a/100;

if(b==c)
cout<<"A Palindrome";
else
cout<<"Not a Palindrome";

getch();

}

Output:

First Run:

Second Run:







For any queries or suggestions please comment !

No comments:

Post a Comment