#Day19- #100DaysChallenge- Matlab Loops| Triangle Pattern:2
#Day19-Triangle Pattern-2
Task:
Print the below pattern using Loops.
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
Take Input from the user for Number of lines in the triangle
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those
Matlab Code:
function triangle_pattern2(x)
k=x-1;
for i=1:1:x
for j=1:1:k
fprintf('\t');
end
for j=1:1:i
fprintf('\t');
fprintf('*');
fprintf('\t');
end
k=k-1;
fprintf('\n');
end
Sample Input and Output
>> triangle_pattern2(5)
*
* *
* * *
* * * *
* * * * *
Join us on Facebook Group: https://www.facebook.com/groups/matlabcodes
No comments