answersLogoWhite

0


Best Answer

#include<iostream>

unsigned int reverse(unsigned int num, unsigned int base=10)

{

unsigned int rev=0;

while( num )

{

rev*=base;

rev+=num%base;

num/=base;

}

return( rev );

}

int main()

{

std::cout<<"Palindromic numbers from 10 to 1000\n"<<std::endl;

for( unsigned int num=10; num<=1000; ++num)

if( num==reverse(num))

std::cout<<num<<std::endl;

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

It is impossible to print all palindromic numbers since numbers are infinite. You should either limit your range of numbers to the maximum number that can be stored in your variable. For example, a 32-bit unsigned int can handle integers in the range 0 to 4,294,967,295 while a 64-bit unsigned int can handle integers in the range 0 to 18,446,744,073,709,551,616. If you need to handle larger integers than this you'd be best advised to implement a user-defined class that can handle the range you desire.

To determine if an integer is palindromic, convert the number to a character array (a string) then set two pointers, one to the first character the other to the last character. While the first point is less than the last pointer and the values being pointed at are the same value, increment the first pointer and decrement the last pointer. If the values differ at any point, the number is not palindromic. When the pointers are equal or pass each other, the number is definitely palindromic.

For example:

bool is_palindrome(std::string num)

{

size_t first = 0;

size_t last = num.size()-1;

while( first<last )

{

if (num[first]!=num[last])

return false; ++first;--last;

}

return true;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

This can be accomplished by the use of nested loops. The outer loop is used to iterate from 1 to 10000 while the inner loop is used to determine the palindrome numbers.

Here is the code snippet:


int i=1, temp, n=10000, rev;

while( i<=n){

temp = i;

rev = 0;

while( temp != 0){

rev = rev*10 + temp%10;

temp /= 10;

}

if( rev == i)

printf("%d\n", i);//printing the palindromic numbers

i++;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c plus plus to display the palindrome numbers between 10 and 1000?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a Program in c to find palindrome numbers between any two numbers?

please somebody should help me answer this question..I have a project on it even! It seems almost impossible at the moment.


What Program that will display the even numbers in data structures and algorithms?

JAVA


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How do you generate palindrome number between the given range?

The generation of palindromic numbers within a given range is best done with a computer program. Space it limited so an example of program code cannot be shown here, but the Codecast website gives full guidance.


How do you write a palindrome program in c in Wikipedia?

You don't have to write palindrome programs in wikipedia.


What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


How do you write a Qbasic program to display these Numbers-0112358132134?

you do this 10 print "0112358132134" use the whole of the thing


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


Write a PHP program to check whether the string is palindrome or not?

You can do this: &lt;?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }


Write an Assembly language program which implements sorting algorithm both ascending and descending order and display those numbers with certain delay say of 5sec between successive displays?

das


Program that display the first 5 odd numbers?

printf("1 3 5 7 9\n");