digitSumAdded (#315)

Co-authored-by: Aayushadh <ayushharwani2011@gmail.com>
This commit is contained in:
Aayush2011
2020-10-01 23:13:27 +05:30
committed by GitHub
parent b1b4c138a6
commit 323db8f292

18
Maths/digitSum.js Normal file
View File

@ -0,0 +1,18 @@
// program to find sum of digits of a number
// function which would calculate sum and return it
function digitSum (num) {
// sum will store sum of digits of a number
let sum = 0
// while will run untill num become 0
while (num) {
sum += (num % 10)
num = parseInt(num / 10)
}
return sum
}
// assigning number
const num = 12345
console.log(digitSum(num))