In: Computer Science
In Matlab , Write a script that will print a side-ways triangle pattern of stars in
the command window. The script should ask the user how many stars will be
between the center of the triangle at the base and the tip of the
triangle
Here according to the question, side-ways triangle pattern of stars with center of base is not getting very much clear. So here two patterns of triangles are given with full programming code, as Pattern 1 and Pattern 2.
Pattern: 1
prompt='How many stars between center of base to tip of the
triangle:';
n=input(prompt);
fprintf('Side-ways triangle pattern of stars is as below\n');
for i = 1:n
for j = 1:i
fprintf('*');
end
fprintf('\n');
end
Pattern:2
prompt='How many stars between center of base to tip of the
triangle:';
n=input(prompt);
k=0;
fprintf('Side-ways triangle pattern of stars is as below\n');
for i = 1:n
for j = 1:n-i
fprintf(' ');
end
for k=0:(2*i-1)-1
fprintf('*');
k=k+1;
end
k=0;
fprintf('\n');
end