ARMSTRONG, PRIME

 PRIME NO :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> TAKE A NUM FIND THE FACTORIAL OF A GIVEN NO USING PROMPT</title>
</head>
<body>


    <script type="text/javascript">
       
a= parseInt(prompt("Prime No Checker: "));
// set count as 0
c=0
// if given no is positive
if(a>0){
    // Loop checking divisability
    for(i=1;i<=a;i++){
        if(a%i==0){
            c=c+1;
        }
    }
    // count set to 2 when it is divided by 1 and itself
    if(c==2){
        document.write(`Given No ${a} is Prime No.`);           
    }
    else{
        document.write(`Given No ${a} is Not a Prime No.`);
    }
}else if(a==0){
    document.write(`Given No ${a} is Not a Prime No.`);
}else{
    document.write(`Please Enter Unsigned No. `);
}
    </script>
</body>
</html>


ARMSTRONG NO:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> TAKE A NUMBER  CHECK THE NO IS armstrong OR NOT</title>
</head>
<body>


<script type="text/javascript">
       
var a=parseInt(prompt("Armstrong No Checker: "));
var num = a;
power = 0;

// find the power
while(num>0){
    power = power +1;
    num = parseInt(num/10);
}

var num=a;
sum = 0;
// calculating sum
while(num>0){
    var remainder = num%10;
    sum = sum + Math.pow(remainder,power);
    num = parseInt(num/10);

}

if(a==sum){
    document.write(`Given No ${a} is Armstrong No.`);           
}
else{
    document.write(`Given No ${a} is Not a Armstrong No.`);
}
</script>
</body>
</html>

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES