write program for palindrome
Answer Posted / vineet
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
#define FALSE 0
#define TRUE 1
int power(int num, int pow)
{
int finalNum = 1;
while(pow)
{
finalNum = finalNum*num;
pow--;
}
return finalNum;
}
bool IsPalindrome1(int n)
{
bool retVal = TRUE;
int indx=0, i=1, a=0;
int arr[10]={0,};
if(0 == (n%10))
return FALSE;
while(n)
{
a=(n%(power(10,i)))/power(10, (i-1));
n = n-(a*power(10,(i-1)));
arr[indx]=a;
indx++;
i++;
}
i--;
for(int j=0;j<=(i/2);j++)
{
if(arr[j] == arr[i-j-1])
retVal = retVal & TRUE;
else
retVal = retVal & FALSE;
}
return retVal;
}
void main()
{
int n=0;
bool b=FALSE;
cout<<" Enter a number to check whether it is a
palindrome or not:";
cin>>n;
b = IsPalindrome2(n);
if(TRUE == b)
cout<<"The number is palindrome"<<endl;
else
cout<<"The number is NOT a
palindrome"<<endl;
getche();
}
| Is This Answer Correct ? | 18 Yes | 28 No |
Post New Answer View All Answers
What are the various compound assignment operators in c++?
Program to check whether a word is a sub-string or not of a string typed
What is a far pointer? where we use it?
What is a hashmap c++?
What are shallow and deep copy?
What are the benefits of c++?
What is operator overloading in c++ example?
What is the difference between cin.read() and cin.getline()?
What is the best c++ compiler for windows 10?
Why the usage of pointers in C++ is not recommended ?
Define copy constructor.
Differentiate between realloc() and free().
What is the latest c++ version?
Define stacks. Provide an example where they are useful.
Which bit wise operator is suitable for turning off a particular bit in a number?