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

Search This Blog

#Day74 #100DaysChallenge- Matlab Loops|Hollow Equilateral Triangle

#Day74-Hollow Equilateral Triangle

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_pattern2(x)

k=x-1;

for i=1:1:x

  

    for sp=1:1:k

        fprintf('\t');

    end

        for j=1:1:i

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

          

            fprintf('\t');

            fprintf('*');

            fprintf('\t');

            else

            fprintf('\t');

            %fprintf('\t');

            fprintf('\t');

               

            end

           

        end

            k=k-1;

            fprintf('\n');

end

    Sample Input and output

>> hollow_triangle_pattern2(5)

*

* *

* *

* *

* * * * *

>> hollow_triangle_pattern2(6)

*

* *

* *

* *

* *

* * * * * *


Click here for Video description





Live Support: t.me/matlabirawen


Join us: https://www.facebook.com/groups/MATLABCODES/   

 

No comments

Popular Posts

Followers