{}
run-icon
main.c
#include <stdio.h> int main() { // Declare variables int num, sum = 0, digit; // Ask the user for a 5-digit number printf("Enter a 5-digit number: "); scanf("%d", &num); // Process the number until it becomes 0 while (num != 0) { // Get the last digit of the number digit = num % 10; // Add the digit to the sum sum = sum + digit; // Remove the last digit from the number num = num / 10; } // Output the sum of the digits printf("Sum of digits = %d\n", sum); return 0; }
Output