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

Search This Blog

#Day90#100DaysChallenge- Matlab Loops | Differentiate Odd and Even lines-2

#Day90-Differentiate Odd and Even lines-2

Task:

Write a code to Differentiate Odd and Even lines.Get user Input for number of rows
r-8;&-odd.*=even
&
**
&&&
****
&&&&&
******
&&&&&&&
********


Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code

function differentiateevenoddlines2(r)

 for i=1:1:r

     if mod(i,2)==0

         for j=1:1:i

             fprintf('*');

         end

     else

         for j=1:1:i

            fprintf('&');

         end

      

     end

     fprintf('\n');

 end

Sample Input and Output

>> differentiateevenoddlines2(8)

&

**

&&&

****

&&&&&

******

&&&&&&&

********              

 

 


Click here for Video description



No comments

Popular Posts

Followers