#Day32 #100DaysChallenge- Matlab Loops| Hollow Diamond-1
#Day32-Hollow Diamond-1
Task:
Print upper part of 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
Matlab code
function upperrightangledtriangle(x)
k=0;
for i=x:-1:1
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
>> upperrightangledtriangle(5)
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
Click Here for Video Description
Free Codes: youtube.com/castorclasses
No comments