I want to make a matlab program to get user between 2 interval and display all armstrong number between 2 number. I saw many online answer only have the program to run 100 to 999 but I want to know how to do it for any numbers

2 views (last 30 days)
I not interested in the answer below instead I want the program to get armstrong number even below 100 and above 999
clear, clc
% Let i take numbers 100 to 999 for i = 100 : 999
% We examine every digit in i
is = num2str(i);
% i1 is the left-most digit in i
i1 = str2num(is(1));
% i2 is the middle digit
i2 = str2num(is(2));
% i3 is the right-most digit in i
i3 = str2num(is(3));
% We calculate the probable AN
an = i1^3 + i2^3 + i3^3;
% We compare to the number itself
if i == an
% We display the pair of equal numbers
disp([i an])
end
end
The results are:
153 153
370 370
371 371
407 407

Answers (1)

Star Strider
Star Strider on 23 Jan 2016
Edited: Star Strider on 23 Jan 2016
Go for it!
This page discusses Armstrong Numbers and gives a simple FORTRAN program that you can easily convert to MATLAB code.
Here’s another discussion of Armstrong numbers.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!