To accept two numbers from the user; Display all prime numbers between these two numbers.
Mostrar comentarios más antiguos
To accept two numbers from the user; Display all prime numbers between these two numbers.
To accept two numbers from the user and display perfect numbers between these two numbers.
To accept two numbers from the user and display Armstrong number between these numbers.
Simple coding using DoWhile, IfElse
Respuesta aceptada
Más respuestas (2)
B.k Sumedha
el 28 de Mayo de 2015
Try this for Armstrong number:
clear, clc
% Let i take two numbers say 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
B.k Sumedha
el 28 de Mayo de 2015
This is for perfect numbers where u can change the values of m and n where they are the two input numbers
n=100;
m=10;
output = zeros(1,n);
for i = m:n
test = 1:i-1;
if (sum(test(mod(i,test) == 0)) == i)
output(i) = i;
end
end
output(output == 0) = []
3 comentarios
B.k Sumedha
el 28 de Mayo de 2015
Did u try with these two?
BeTrayer EK
el 28 de Mayo de 2015
BeTrayer EK
el 28 de Mayo de 2015
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!