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

Search This Blog

#Day73 #100DaysChallenge- Matlab Loops|Hollow Right angled Triangle

#Day73-Hollow Right angled 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 hollowrightangledtriangle(n)
for i=1:1:n
    for j=1:1:i

        if j==1 || j==i||i==n
            fprintf('*');
            fprintf('\t');
        else
                fprintf('\t');
        end
    end
                fprintf('\n');
end
               
Sample Input and Output
>> hollowrightangledtriangle(5)
*
* *
* *
* *
* * * * *
>> hollowrightangledtriangle(3)
*
* *
* * *
>> hollowrightangledtriangle(7)
*
* *
* *
* *
* *
* *
* * * * * * *
>>  
Click here for video description



No comments

Popular Posts

Followers