Page

Program to print the sum of digits of given number in java script

<html>
<head><h2><center>program to print the sum of digits of given number</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the number"," "));
sum=0;
x=n;
while(n>0)
{
m=n%10;
n=n/10;
sum=parseInt(sum+m);
}

document.write("the sum of digits of "+"     "+x+"   "+"is   "+"     "+sum);
</script>
</body>
</html>

No comments:

Post a Comment