In this Hackerrank Sum of Digits of a Five Digit Number problem, we have given a five-digit integer, and we need to print the sum of its digits on the output screen. 


HackerRank Sum of Digits of a Five Digit Number problem solution in c

HackerRank Sum of Digits of a Five Digit Number problem solution in c

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
   
    int n;
    scanf("%d", &n);
    //Complete the code to calculate the sum of the five digits on n.
    int sum = 0;
    do {
        sum += (n % 10);
        n /= 10;
    }
    while(n != 0);
    printf("%d", sum);
    return 0;
}