coder18s,blogspot.com

Powered by Blogger.

8.Sum of Digits of a Five Digit Number Hackerrank Solution

Task

Given a five digit integer, print the sum of its digits.

Sample Input 

10564

Sample Output 

16
                Program Code 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    
     int n,rem,sum = 0;
    scanf("%d", &n);
 
    while(n > 0)
    {
        rem = n %10;
        sum = sum + rem;
        n = n/10;
    }
    printf("%d",sum);
    return 0;
}