HOME

Monday, November 7, 2016

WML program to find whether number is prime or not.

#WML FILE
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<card id="card1">
<p>
<do type="accept" label="Check Number">
<go href="prime.wmls#check()"/>
</do>
</p>
</card>
</wml>


#WMLS SCRIPT FILE
    extern function check()
    {

    var num=Dialogs.prompt("Enter Number",0);
    var n=Lang.parseInt(num);
        if(n==1)
        {
        Dialogs.alert("It is prime number");
        }
        else{
        var c=0;
    for(var i=1;i<=n;i++)
    {
    if(n%i==0)
    {
    c=c+1;
    } 
    }
    if(c==2)
    {
    Dialogs.alert("It is prime Number");
    }
    else
    {
    Dialogs.alert("It is not a prime number");
    }
    }
    }

No comments:

Post a Comment