C Online Compiler
Example: Sum of Digits of a Number in C using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Digits of a Number in C using For 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); for (int i = x; i > 0; i = i/10) { m = i%10; sum = sum+m; } printf ("%d\n", sum); return 0; }
3579
Output
Clear
ADVERTISEMENTS