#Day57 #100DaysChallenge- Matlab Loops|Floyd's Triangle
#Day57-Floyd's Triangle
Task:
Task:
Write a code to Print Floyd's Triangle.Get user Input for Number of rows.
1
01
101
0101
10101
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
01
101
0101
10101
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
function trainglewith01(x)
 for i=1:1:x
     if mod(i,2)==0
         k=0;
         d=1;
         for j=1:1:i
             fprintf('%d',k)
             temp=k;
             k=d;
             d=temp;
         end
     else
         k=1;d=0;
         for j=1:1:i
             fprintf('%d',k)
             temp=k;
             k=d;
             d=temp;
         end
     end
fprintf('\n');
end
>> trainglewith01(6)
1
01
101
0101
10101
010101
>> trainglewith01(5)
1
01
101
0101
10101
>> trainglewith01(10)
1
01
101
0101
10101
010101
1010101
01010101
101010101
0101010101
 
 
 
 
 
 
 
%206th%20Edition,%20Kindle%20Edition.jpg) 
 
 
 Posts
Posts
 
 
 
 
 
 
 
 
No comments