#include <stdio.h>
int main() {
int num, sum = 0, reversed_num = 0, temp;
// Get input from the user
printf("Enter an integer: ");
scanf("%d", &num);
// Calculate the sum of digits
temp = num; // Store the original number for sum calculation
while (temp > 0) {
sum += temp % 10; // Add the last digit to sum
temp /= 10; // Remove the last digit
}
printf("Sum of digits: %d\n", sum);
// Check if the original number is a palindrome
temp = num; // Reset temp to the original number for palindrome check
while (temp > 0) {
reversed_num = reversed_num * 10 + temp % 10; // Build the reversed number
temp /= 10; // Remove the last digit
}
if (num == reversed_num) {
printf("%d is a palindrome.\n", num);
} else {
printf("%d is not a palindrome.\n", num);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIGludCBudW0sIHN1bSA9IDAsIHJldmVyc2VkX251bSA9IDAsIHRlbXA7CgogICAgLy8gR2V0IGlucHV0IGZyb20gdGhlIHVzZXIKICAgIHByaW50ZigiRW50ZXIgYW4gaW50ZWdlcjogIik7CiAgICBzY2FuZigiJWQiLCAmbnVtKTsKCiAgICAvLyBDYWxjdWxhdGUgdGhlIHN1bSBvZiBkaWdpdHMKICAgIHRlbXAgPSBudW07IC8vIFN0b3JlIHRoZSBvcmlnaW5hbCBudW1iZXIgZm9yIHN1bSBjYWxjdWxhdGlvbgogICAgd2hpbGUgKHRlbXAgPiAwKSB7CiAgICAgICAgc3VtICs9IHRlbXAgJSAxMDsgLy8gQWRkIHRoZSBsYXN0IGRpZ2l0IHRvIHN1bQogICAgICAgIHRlbXAgLz0gMTA7ICAgICAgLy8gUmVtb3ZlIHRoZSBsYXN0IGRpZ2l0CiAgICB9CiAgICBwcmludGYoIlN1bSBvZiBkaWdpdHM6ICVkXG4iLCBzdW0pOwoKICAgIC8vIENoZWNrIGlmIHRoZSBvcmlnaW5hbCBudW1iZXIgaXMgYSBwYWxpbmRyb21lCiAgICB0ZW1wID0gbnVtOyAvLyBSZXNldCB0ZW1wIHRvIHRoZSBvcmlnaW5hbCBudW1iZXIgZm9yIHBhb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