ARMSTRONG NUMBER
************************************************************************
W.A.P TO CHECK ARMSTRONG NUMBER
************************************************************************
JAVA Program
Output:
************************************************************************
C Program
Online Compiler
************************************************************************
C++ Program
Online Compiler
************************************************************************
C# Program
************************************************************************
PHP Program
Php is a server side scripting language.
************************************************************************
JAVASCRIPT Program
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title>
<script type="text/javascript">
// ARMSTRONG NUMBER
// 153 = 1*1*1 + 5*5*5 + 3*3*3
//1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, are armstng no.
function check() {
var number= document.getElementById('n1').value;
var sum =0;
var temp = number;
var noOfDigits = number.toString().length;
while(temp>0){
var digit = temp%10; // 153%10 =3
sum += digit**noOfDigits;
temp= parseInt(temp/10);
}
if (sum==number)
{
document.getElementById('ans').innerText=`${number} is an armstrong number`;
}
else
{
document.getElementById('ans').innerText=`${number} is not an armstrong number`;
}
}
function check2()
{
var a = document.getElementById('n2').value;
var b = document.getElementById('n3').value;
var res="";
// console.log(typeof(a));
for (var i=parseInt(a); i<=parseInt(b); i++){
var sum =0;
var temp =i;
var noOfDigits = i.toString().length;
while(temp>0){
var digit = temp%10; // 153%10 =3
sum += digit**noOfDigits;
temp= parseInt(temp/10);
}
if (sum == i)
{
console.log(i);
res = res.concat(`${i}, `);
}
}//for
document.getElementById('ans2').innerText=
`Armstrong Numbers are ${res} `;
}
</script>
</head><body>
Armstrong Number Checker
<br>
<input type="number" name="" id="n1"/>
<br>
<button onclick="check()">CALCULATE</button>
<h2 id="ans" ></h2>
<br><br><br><br><br>Armstrong Number
<br>
Starting Value <input type="number" name="" id="n2"/><br>
Ending Value<input type="number" name="" id="n3"/>
<br>
<button onclick="check2()">CALCULATE</button>
<h2 id="ans2" ></h2>
</body></html>
************************************************************************
PYTHON Program
************************************************************************
Comments
Post a Comment