16)Write a menu driven program to perform the following options using JavaScript: 1. To find Armstrong numbers between 1 to 1000. 2. To print sum of the digit of a number.


<HTML>
<HEAD>
<TITLE>MenuDriven</TITLE>
</HEAD>

<BODY>
<H1> Menu Driven Program For Armstrong and sum of digits</H1>
<p>
<SCRIPT>
var i,j,r,ch;
var n;
var sum=0;

ch=parseInt(prompt(“Enter 1 for Armstrong number and 2 for sum of digits”));
switch(ch)

{

case 1:
document.write(“Armstrong Number :- “);
for(i=1;i<=1000;i++)
{
j=i;
sum=0;
while(j>0)
{
r=j%10;
sum=sum+(r*r*r);
j=parseInt(j/10);
}
if( sum==i)
{
document.write(sum+” , “);
}
}
break;
case 2:
n=parseInt(prompt(“Enter any number for finding sum of digits”));
while(n>0)
{
sum=sum+n%10;
n=parseInt(n/10);
}
document.write(“<br>”+”Sum of digits= “+sum);
break;
default :
alert(“Wrong choice”);
}

</SCRIPT>
</BODY>
<HTML>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s