+ 3
Why my Code doesn't work!? Please help
I want to print Palindrome Numbers within an Arbitrary Range. I have checked this code for one single number, and it has no problem. Help Me, Friends!!! https://code.sololearn.com/c0x29nmkYlHK/?ref=app
2 Answers
+ 3
correct code is:
#include <stdio.h>
int main() {
unsigned long number, reversedInteger = 0;
unsigned long remainder;
unsigned long originalInteger;
unsigned long LB = 0, UB = 0;
int count = 0;
printf("Enter A Range To Check For Palindromes . . . . . . . . ");
scanf("%ld" , &LB);
scanf("%ld" , &UB);
printf("\n Lower Bound = %ld" , LB);
printf("\n Upper Bound = %ld" , UB);
printf("\n\n Palindrome Numbers In Range %ld To %ld:\n" , LB , UB);
for(unsigned long i=LB;i<=UB;i++)
{
number = i;
originalInteger = number;
reversedInteger =0;
while(number != 0)
{
remainder = number % 10;
reversedInteger = reversedInteger*10 + remainder;
number /= 10;
}
if (originalInteger == reversedInteger)
printf(" %ld ", originalInteger);
}
return 0;
}
+ 3
Thanks man, my mistake was reversedInteger. Its value must set to 0 at the beginning of for loop.