Explanation:The required library is included.
Sum is used to store the total, digit is used for each individual digit, and num is used for input.
Entering an integer and reading it is what we ask of the user.
We extract and add the final digit to total, looping until num equals 0.
We output the final sum once we have processed every digit.
#include <stdio.h>
int main() {
int num, sum = 0, digit;
printf("Enter an integer: ");
scanf("%d", &num);
while (num != 0) {
digit = num % 10; // Get the last digit.
sum += digit; // Add it to the sum.
num /= 10; // Remove the last digit.
}
printf("Sum of digits: %d\n", sum); // Output the sum.
return 0;
}