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

Search This Blog

#Day93#100DaysChallenge- Matlab Loops | Plus Symbol

#Day93-Plus Symbol

Task:

Write a code for plus symbol pattern as shown below.Get user Input for number of rows

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

Matlab code

function plussymbol(x)

for i=1:1:x

    if i==floor(x/2)       

          

            for j=1:1:x

                fprintf('+');

                fprintf('\t');

            end

    else

                    for space=1:1:floor(x/2)

                        fprintf('\t');

                    end

                        fprintf('+');

    end

                        fprintf('\n');

end

 

Sample Input and Output

>> plussymbol(15)

+

+

+

+

+

+

+ + + + + + + + + + + + + + +

+

+

+

+

+

+

+

+


Click here for Video description




No comments

Popular Posts