#Day14- #100DaysChallenge- Matlab Loops| Zig-Zag Pattern
#Day14- ZigZag Pattern
Task: Print ZigZag pattern with the specified size, length, and character.
Staking greater than symbol forms zig-zag line, Take input from the user how much greater than symbol to be stacked and how big the symbol should be and also which character should be incorporated.
Example
zigzag(4,3,'$')
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those
Matlab code:
function zigzag(inc,length_leg,y)
while inc>0
for i=1:1:length_leg
for j=1:1:i
fprintf('\t')
end
fprintf(y);
fprintf('\n');
end
for i=length_leg:-1:1
for j=1:1:i
fprintf('\t')
end
fprintf(y);
fprintf('\n');
end
inc=inc-1;
end
Sample Input and Output
>> zigzag(4,3,'@')
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
>> zigzag(4,3,'K')
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
K
>> zigzag(4,3,'9')
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
Click Here for Video Description
Join us on Facebook Group:https://www.facebook.com/groups/matlabcodes
No comments