C Online Compiler
Example: Sum of Digits of a Number in C using Do While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Digits of a Number in C using Do While loop #include <stdio.h> int main() { int x, sum = 0, m; printf ("Enter the integer number::\n"); scanf ("%d", &x); printf ("The sum of %d digits is = ", x); do { m = x%10; sum = sum+m; x = x/10; } while (x > 0); printf ("%d\n", sum); return 0; }
4523
Output
Clear
ADVERTISEMENTS