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

Search This Blog

#Day92#100DaysChallenge- Matlab Loops | Steps Pattern-2

#Day92-Steps Pattern-2

Task:

Write a code for Steps Pattern as shown below.Get user Input for number of rows
       *
**
***
****
*****
******
*****
****
***
**
*

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code

function pattern_steps2(x)

 

inc=1;

space=1;

 

 

for i=1:1:x-1

  

        for space=1:1:space

            fprintf('\t');

        end

        for j=1:1:inc

            fprintf('*');

        end

        inc=inc+1;

        space=space+1;

        fprintf('\n');

                         

 

end

for i=1:1:x+1

    for space=1:1:space

        fprintf('\t');

    end

        for j=1:1:inc

            fprintf('*');

        end

            inc=inc-1;

            space=space-1;

            fprintf('\n');

end

 

Sample Input and Output 

>> pattern_steps2(6)

*

**

***

****

*****

******

*****

****

***

**

*

Click here for video description





Live Support: t.me/matlabirawen




No comments

Popular Posts

Followers