Day 35: Sum of all digits of a Number of 100DaysCodingChallenge
Hello all,
I have started the 100 days of coding challenge to improve my programming skills..
Today is the Day35 of 100DaysCodingChallenge for
Sum of all digits of a Number input Numbers taken by the user.
Code :
let n = prompt("Enter a Number : ");
let sum = s = 0;
let n1 = n;
while (n > 0) {
  s = n % 10;
  sum = sum + s;
  n = Math.floor(n/10);
}
console.log("The Sum of all digits of Number", n1, "is :", sum);Output :
Happy Coding:)

 
 
 
Comments
Post a Comment