Write a C program to reverse the digits of a given number and add it to the original, If the sum is not a palindrome repeat this procedure.
#include <stdio.h>
int Reversed(int n) {
int reversed = 0;
while (n) {
reversed *= 10;
reversed += n % 10;
n /= 10;
}
return reversed;
}
int Magic(int n) {
int sum = n + Reversed(n);
if (Reversed(sum) != sum) {
return Magic(sum);
}
return sum;
}
int main() {
int n;
scanf("%d", &n);
int res = Magic(n);
printf("final: %d", res);
return 0;
}
Comments