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 is the difference between an array and a list?
What is the average salary of a c++ programmer?
What do you understand by a pure virtual member function?
How do you declare A pointer to a function which receives nothing and returns nothing
What do you understand by zombie objects in c++?
Is c++ a float?
What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random
What are iterators in c++?
On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?
Tell me an example where stacks are useful?
What is a singleton class c++?
What is the limitation of cin while taking input for character array?
How can we check whether the contents of two structure variables are same or not?
What is runtime polymorphism in c++?
What are the advantages of using a pointer?