Write a MATLAB script that will build a triangle of symbols. This program should
ID: 3759132 • Letter: W
Question
Write a MATLAB script that will build a triangle of symbols. This program should allow for the user to specify the symbol to use, and should accept any character or string value. It should also enable the user to select the height of the triangle built.
Finally, the program should enforce the user to only use a single character as the symbol. An example of the execution and output is below.
Specify a character to print in your loop: Tx How tall would you like your image? 4 Please input only a single character: Ty Please input only a single character: T T TT TTT TTTT
Explanation / Answer
sym = input('Specify a character to print in your loop:','s');
tall = input('How tall would you like your image?');
while length(sym) ~= 1
sym = input('Please input only a single character:','s');
end
temp = 1;
res = '';
while temp <= tall
res = [res, sym];
disp(res)
temp = temp + 1;
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.