code to accept 2 numbers and to display armstrong number between the 2?
Show older comments
I'm new to mathlab and i have Absolutely no idea how to write this code. I don't want to use functions and prefer to use loops to solve this. But at this point anything goes.
Accepted Answer
More Answers (2)
Bhuvana Krishnaraj
on 9 Jan 2020
Edited: Bhuvana Krishnaraj
on 9 Jan 2020
1 vote
x=input('Enter number: ');
disp(x)
temp=x;
y = 0;
h=fprintf('%d',x); %% it return number of digits
while x > 0
t = mod(x,10);
y = y+t^h;
x = (x-t)/10;
end
if(y==temp)
disp('Amstrong');
else
disp('not amstrong');
end
Bhuvana Krishnaraj
on 9 Jan 2020
0 votes
x=input('Enter number: ');
disp(x)
temp=x;
y = 0;
while x > 0
t = mod(x,10);
y = y+t^3;
x = (x-t)/10;
end
if(y==temp)
disp('Amstrong');
else
disp('not amstrong');
end
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!