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

Search This Blog

#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

Matlab code
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)



* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
Click Here for Video Description




Free Codes: youtube.com/castorclasses


Live Support: t.me/matlabirawen



No comments

Popular Posts

Followers