Code
HackerRank - Sum of Digits of a Five Digit Number
· ☕ 2 min read
Introduction Given a five digit integer, print the sum of its digit Input: 5 digit number, n Output: sum of 5 digit number Input and Output Format # Input 10564 # Output 16 {: file="Sum Of Digits of a Five Digit Number.c” } $1+0+5+6+4=16$ This is a watered-down version of the question {: .prompt-info } Process This was my thought process while attempting this challenge. Calculate the number of digits By dividing the number by 10 and incrementing a counter in a while loop The number of digits can be found In a for loop to loop through the total number of digits (5) sum += number % 10 number /= 10 This is to remove the LSB of the number for each iteration of the loop Print out the sum Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include <stdio.