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

Search This Blog

#Day36 #100DaysChallenge- Matlab Loops| Special Triangle

#Day36-Special Triangle

Task:
Print special triangle with numeric's   as shown below by taking user input for the number of lines or rows
1
1 1
1 2 1
1 2 3 1
1 2 3 4 1
1 2 3 4 5 1
1 2 3 4 5 6 1
1 2 3 4 5 6 7 1
1 2 3 4 5 6 7 8 1

1 2 3 4 5 6 7 8 9 1
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those
Matlab code


function specialtraingle(x)

k=x;
for i=1:1:x
    for k=1:1:k
        fprintf('\t');
    end
        for j=1:1:i-1
            fprintf('%d',j);
            fprintf('\t');
        end
            fprintf('%d',1);
            fprintf('\t');
            fprintf('\n');
            k=k-1;
end
 Sample Input and Output
>> specialtraingle(6)

1
1 1
1 2 1
1 2 3 1
1 2 3 4 1
1 2 3 4 5 1
>> specialtraingle(8)
1
1 1
1 2 1
1 2 3 1
1 2 3 4 1
1 2 3 4 5 1
1 2 3 4 5 6 1
1 2 3 4 5 6 7 1

Click here for Video Description





Live Support: t.me/matlabirawen



No comments

Popular Posts

Followers