Search This Blog

#Day76 #100DaysChallenge- Matlab Loops|Hollow Triangle Pattern 4


#Day76-Hollow  Triangle Pattern 4

Task:

Write a code to Print a hollow triangle pattern as shown below
* * * * * *
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code 


function hollow_triangle_pattern4(x)

for i=x:-1:1

    for j=1:1:i

        if j==1||j==i||i==x

            fprintf('\t');

            fprintf('*');

        else

            fprintf('\t');

        end

    end

    fprintf('\n');

end

 

 Sample Input and Output

>> hollow_triangle_pattern4(6)

* * * * * *

* *

* *

* *

* *

*

>> hollow_triangle_pattern4(5)

* * * * *

* *

* *

* *

*

Click here for Video description




No comments

MATLAB