#Day43 #100DaysChallenge- Matlab Loops|Triangle Pattern With Number
#Day43-Triangle Pattern With Number
Task:
Task:
Write a code to generate a triangular pattern with number.Take user input for number of rows.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
             Sample Input and Output 
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
function triangle_patternwithbumber(x)
k=x-1;
for i=1:1:x
    num=0;
    for j=1:1:k
        fprintf('\t');
    end
        for j=1:1:i
            num=num+1;
            fprintf('\t');
            fprintf('%d',num);
            fprintf('\t');
        end
            k=k-1;
            fprintf('\n');
end
>> triangle_patternwithbumber(5)
     1 
    1  2 
   1  2  3 
  1  2  3  4 
 1  2  3  4  5 
Click here for Video Description
 
 
 
 
 
 
 
%206th%20Edition,%20Kindle%20Edition.jpg) 
 
 
 Posts
Posts
 
 
 
 
 
 
 
 
No comments