Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c Program for Sum of the digits of a given number

// C program to compute sum of digits in
// number.
#include <stdio.h>
 
/* Function to get sum of digits */
int getSum(int n)
{
    int sum = 0;
    while (n != 0) {
        sum = sum + n % 10;
        n = n / 10;
    }
    return sum;
}
 
// Driver code
int main()
{
    int n = 687;
    printf(" %d ", getSum(n));
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Program #Sum #digits #number
ADD COMMENT
Topic
Name
1+6 =