#include <stdio.h> // Main body of the program int main() { // Declare the variables int number, sum = 0; scanf("%d", &number); // Loop using a while statement // The loop will run till the number is not equal to 0 while (number != 0) { // Sum plus the number divided by 10 to skip a place sum += number % 10; // Number is divided by 10 number = number / 10; } // Print the sum of the number printf("%d\n", sum); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter