Sum of Digits of a five Number Digit || Hacker Rank

 Question 8 || Hacker Rank

Sum of Digits of a five Number Digit || Hacker Rank

Sum of Digits of a five Number Digit


Objective

The modulo administrator, %, returns the rest of a division. For instance, 4 % 3 = 1 and 12 % 10 = 2. The standard division administrator,/, returns a shortened number worth when performed on whole numbers. For instance, 5/3 = 1. To triumph ultimately the last digit of a number in base 10, use as the modulo divisor.

Task

Given a five digit number, print the amount of its digits.

Input Organization

The information contains a solitary five digit number, .

Limitations

Yield Organization

Print the amount of the digits of the five digit number.

Test Info 0

10564
Test Result 0

16


#include <stdio.h>

int main() {
    
    int n,rem,count = 0;
    scanf("%d", &n);
    if (n >= 10000 && n <= 99999)
    {
        for (int i = 0; i < 5; i++)
        {
            rem=n % 10;
            count = count + rem;
            n = n / 10;
        }
    }
    printf("%d \n", count);
    return 0;
}


Output


Sum of Digits of a five Number Digit



Post a Comment

0 Comments