Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#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)
*
* *
* * *
* * * *
* * * * *
Click Here for Video Description



Join us on Telegram: https://t.me/matlabirawen
Join us on Facebook Group: https://www.facebook.com/groups/matlabcodes


No comments

Popular Posts