HOME

Thursday, November 10, 2016

WML program to check whether given number is armstrong or not.

#WML file
<?xml version="1.0" ?>
<wml>
<card id="card1" title="armstrong number">
<do type="accept" label="Check Number">
<go href="function.wmls#check()"/>
</do>
</card>
</wml>

#WMLS file
extern function check()
{
var number=Dialogs.prompt("Enter Number",0);
var n=Lang.parseInt(number);
var num=n;
var sum=0;
var rem;
if(n==0)
{
Dialogs.alert("It is not a armstrong Number");
}
else if(n>=1 && n<=9)
{
Dialogs.alert("It is armstrong Number");
}
else
{
while(n>0)
{
rem=n%10;
sum+=rem*rem*rem;
n=n div 10;
}
if(sum==num)
{
Dialogs.alert("It is armstrong Number");
}
else
{
Dialogs.alert("It is not armstrong Number");
}
}
}

No comments:

Post a Comment