Sum of Digits of a Five Digit Number Discussions | C | HackerRank

Sum of Digits of a Five Digit Number

  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    int main() {
    	
        int num;
        // scanf("%d", &n);
        //Complete the code to calculate the sum of the five digits on n.
        // int num;
        scanf("%d", &num);
        int sum = 0;
        
        while (num > 0) {
        int digit = num % 10;
        sum += digit;
        num /= 10;
        }
        printf("%d", sum);
        return 0;
    }