How to write a loop that spells the word “aluminum,” adding one letter at a time?

3 views (last 30 days)
Answer should appear similar to this: a al alu alum alumi alumin aluminu aluminum

Accepted Answer

Stephen23
Stephen23 on 17 Dec 2015
Edited: Stephen23 on 17 Dec 2015
>> S = 'aluminium';
>> for k = 1:numel(S), disp(S(1:k)), end
a
al
alu
alum
alumi
alumin
alumini
aluminiu
aluminium
If you actually want to learn how to write your own MATLAB code and not just get other people to do your homework for you, then you should do these tutorials:

More Answers (0)

Categories

Find more on Variables 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!