# 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.

Expert's answer

#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;

}

#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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment