fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int num, sum = 0, reversed_num = 0, temp;
  5.  
  6. // Get input from the user
  7. printf("Enter an integer: ");
  8. scanf("%d", &num);
  9.  
  10. // Calculate the sum of digits
  11. temp = num; // Store the original number for sum calculation
  12. while (temp > 0) {
  13. sum += temp % 10; // Add the last digit to sum
  14. temp /= 10; // Remove the last digit
  15. }
  16. printf("Sum of digits: %d\n", sum);
  17.  
  18. // Check if the original number is a palindrome
  19. temp = num; // Reset temp to the original number for palindrome check
  20. while (temp > 0) {
  21. reversed_num = reversed_num * 10 + temp % 10; // Build the reversed number
  22. temp /= 10; // Remove the last digit
  23. }
  24.  
  25. if (num == reversed_num) {
  26. printf("%d is a palindrome.\n", num);
  27. } else {
  28. printf("%d is not a palindrome.\n", num);
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Enter an integer: Sum of digits: 22
32764 is not a palindrome.