Slip 4 - A) Write a java script program to accept a number from user and check whether it is Armstrong number or not

Solution:

<HTML>

<body>

<script>

function sum()

{

var sum=0;

var no=parseInt(frm.txt1.value);

while(no>0)

{

sum=sum+no%10;

no=Math.floor(no/10);

}

alert("Sum of digits  "+sum);   

 }

</script>

<form name="frm">

Enter a Number:<input name="txt1" type="text" />

<input name="b1" onclick="sum();" type="button" value="display" /></form>

</BODY>

</HTML>

Post a Comment

0 Comments