Answer to Question #24871 in C++ for Ashmita baidya

Question #24871
Q1)Given a list of integer, write a program to find those which are palindrome.
1
Expert's answer
2013-02-21T10:09:32-0500
#include <iostream>

#include <conio.h>
using namespace std;
unsigned int flip(unsigned int n)
{
int i, newInt = 0;
for (i=0; i<4; ++i)
{
newInt += (n & 0x0001);
newInt <<= 1;
n >>= 1;
}
return newInt;
}
bool isPalindrome(int n)
{
int flipped = flip(n);
/* shift to remove trailing zeroes */
while (!(flipped & 0x0001))
flipped >>= 1;
return n == flipped;
}

int main()
{
int numbers[5];
numbers[0]=1111;
numbers[2]=1451;
numbers[3]=5649;
numbers[3]=9999;
for(int i=0;i<4;i++){
if(isPalindrome(numbers[i])==true){
cout<<"
IS palindrom";
}else{
cout<<"
IS not palindrom";
}

}


getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS