Skip to content

Commit b7156b6

Browse files
authored
Merge pull request #57 from kNOzone/patch-1
Create is_armstrong.m
2 parents 143cd7e + 43e81f3 commit b7156b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

algorithms/maths/is_armstrong.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%% Armstrong no
2+
3+
function n= is_armstrong(num)
4+
if(num<0)
5+
n=0; %as negative no can't be armstrong
6+
end
7+
sum=0;
8+
temp=num;
9+
while(temp>0)
10+
sum=sum*10 + rem(temp,10);
11+
temp=fix(temp/10);
12+
end
13+
if(sum==num)
14+
n=1; % the no is armstrong
15+
else
16+
n=0; % the no is not armstrong
17+
end
18+
end

0 commit comments

Comments
 (0)