C Online Compiler
Example: Sum of Digits of a Number in C using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Digits of a Number in C using Function #include <stdio.h> // This function will make sum of digits of number itself void DigitSum(int x) { int sum = 0, m; printf ("The sum of %d digits is = ", x); while (x > 0) { m = x%10; sum = sum+m; x = x/10; } printf ("%d\n", sum); } // It's the driver function int main() { int x; printf ("Enter the integer number::\n"); scanf ("%d", &x); DigitSum(x); return 0; }
12345
Output
Clear
ADVERTISEMENTS