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

Sum of Digits of a Five Digit Number

  • + 0 comments

    include

    include

    include

    include

    int main() { int n; int sum = 0;

    scanf("%d", &n);
    
    // Loop to calculate the sum of the five digits
    for (int i = 0; i < 5; i++) {
        int remainder = n % 10;
        sum += remainder;
        n /= 10;
    }
    
    printf("%d\n", sum);
    return 0;
    

    }