Using the original posted code as the template:
Code:
/*flip (reverse) the number entered and add it to the last tally. Count the
steps needed (and numbers), until you reach a sum that is the reverse
of itself:
eg: 125 entered: 125+521=646,
646 == it's reverse, so only 1 step was needed.
679 + 976 = 1655
1655 + 5561 = 7216
7216 + 6127 = 13343
13343 + 34331 = 47674
4 steps
*/
#include <stdio.h>
int a[10] = { 0 };
int main() {
int count=0, i, j, bad;
unsigned long int temp, sum;
unsigned long int num ;
unsigned long int f_num = 0; //flipped number
printf("\n\n\n Enter a Number: ");
scanf("%U",&num);
do{
num=num+f_num;
f_num = 0;
temp=num;
while(temp) {
f_num = 10 *f_num + temp % 10;
temp /= 10;
}
count++;
printf("\n num=%lu f_num=%lu count=%d",num,f_num,count);
//flip the sum into array a[]
sum = num + f_num;
temp = sum;
for(i = 0; i < 10; i++)
a[i] = 0;
i = 0;
while(temp) {
a[i] = 10 * a[i] + temp % 10;
i++;
temp /= 10;
}
i -= 1;
for(j = 0, bad = 0;j < i; j++, i--) {
if(a[j] != a[i]) {
bad = 1;
break;
}
}
} while (bad);
printf(" sum: %lu", sum);
getch();
return 0;
}