#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;
}
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 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++;
}
JAVA
To write a C++ program to display the student details using class and array of object.
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.
You don't have to write palindrome programs in wikipedia.
PRINT 2,3,5,7,11,13,17,19,23,29,31,37
please somebody should help me answer this question..I have a project on it even! It seems almost impossible at the moment.
JAVA
To write a C++ program to display the student details using class and array of object.
By learning how to program on C+.
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.
You don't have to write palindrome programs in wikipedia.
PRINT 2,3,5,7,11,13,17,19,23,29,31,37
you do this 10 print "0112358132134" use the whole of the thing
VBnet program to find the prime numbers between 100 to 200?
You can do this: <?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }
das
printf("1 3 5 7 9\n");