Skip to content

Commit

Permalink
Code to find Armstrong Number in an array
Browse files Browse the repository at this point in the history
Given an array of n elements to find the Armstrong in it
  • Loading branch information
Arunkumar1712 authored Jan 4, 2024
1 parent 0d801ce commit 212817a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions armstrongnoinarr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var arr=[143,153,345,1634]
for(var i=0;i<arr.length;i++){
var n=arr[i];
var p=0;
var n1=n;
var ch=n;
while(n>0){
n=parseInt(n/10);
p++
}
var r;
var r1;
var ans=0;
while(n1>0){
r1=n1%10;
ans+=r1**p;
n1=parseInt(n1/10);
}
if(ch===ans){
console.log(ans)}}

0 comments on commit 212817a

Please sign in to comment.