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


Please Help Members By Posting Answers For Below Questions

What are advantages of c++?

772


What is c++ virtual inheritance?

810


What is const in c++?

790


What are friend classes? What are advantages of using friend classes?

840


Const char *p , char const *p What is the difference between the above two?

914


What is an iterator class in c++?

847


How does java differ from c and c++?

722


Can I learn c++ without c?

879


Implement stack operations with pointers with appropriate exception checks.

755


What is switch case in c++ syntax?

821


Explain overriding.

769


What is a storage class used in c++?

810


What is isdigit c++?

834


What are move semantics?

864


What do you mean by inheritance in c++? Explain its types.

813