Write a Matlab code to check. .. whether a given number is an amstrong number using functions.
69 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
need code
0 Commenti
Risposte (2)
Murugan C
il 1 Feb 2022
function check_amstrong_number(input)
if isnumeric(input)
input_ams = num2str(input);
else
error('Input shoud be numberic')
end
amst_num = 0;
for i1 = 1 : length(input_ams)
amst_num = amst_num + str2double(input_ams(i1)) ^ 3;
end
if amst_num == input
disp(['Given Number ' input_ams ' is Amstrong_Number'])
else
disp(['Given Number ' input_ams ' is NOT a Amstrong_Number'])
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Direct Search in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!