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> // Function to make sum of each digits int sum_of_digits(int num) { int sum = 0, mod; while (num > 0) { mod = num % 10; sum += mod; num = num / 10; } return sum; } // It's the main function of the program int main() { int num; // Step-1 Enter a Number printf("Enter Number: "); scanf("%d", &num); // Step-2 Call the sum_of_digits() function to get the sum of each digits // & print the final output of the program printf("\nOutput: %d", sum_of_digits(num)); return 0; }
654
Output
Clear
ADVERTISEMENTS