#Day33 #100DaysChallenge- Matlab Loops| Hollow Diamond-2
#Day33-Hollow Diamond-2
Task:
Print lower part of a hollow diamond as shown below by taking user input for the number of lines or rows
* ** * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those
function lowerrightangledtirangle(x)
k=x+(x-2);
for i=1:1:x
for j=1:1:i
fprintf('\t');
fprintf('*');
end
for g=1:1:k
fprintf('\t');
end
for sj=1:1:i
fprintf('\t');
fprintf('*');
end
fprintf('\n');
k=k-2;
end
end
Sample Input and Output
>> lowerrightangledtirangle(10)
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
No comments