You are on page 1of 3

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? 7
Please input only a single character: Ty
Please input only a single character: T
T
TT
TTT
TTTT
TTTTT
TTTTTT
TTTTTTT
Answer:
Program for triangle symbol

clc
clear all
close all
n=input('Enter n=');
for i=1:n;
for j=1:j-1
fprintf(' T');
fprintf('');
end
fprintf('\n');
end
The program should enforce the user to only use a single character as the symbol.

clc
clear all
close all
x = [];
for i = 1 : 7
x = strcat(x,'Tx');
disp(x)
end

clc
clear all
close all
x = [];
for i = 1 : 7
x = strcat(x,'Ty');
disp(x)
end
clc
clear all
close all
x = [];
for i = 1 : 7
x = strcat(x,'T');
disp(x)
end