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

Search This Blog

#Day22 #100DaysChallenge- Matlab Loops| Right angled Triangle:4

#Day22-Right Angled Triangle:4

Task:

Print Right angled Triangle as shown below by taking user input for number of lines.

                               *    *              *              *              *              *              *              *             *               *         

                                                *              *              *              *              *              *              *              *              *

                                                                *              *              *              *              *              *              *              *

                                                                                *              *              *              *              *              *              *

                                                                                                *              *              *              *              *              *

                                                                                                                *              *              *              *              *

                                                                                                                                *              *              *              *

                                                                                                                                                *              *              *

                                                                                                                                                                *              *

                                                                                                                                                                                *



Matlab Code:


function rightangledtriangle_4(x)

k=0;

for i=x:-1:1

    k=k+1;

    for jj=1:1:k

        fprintf('\t');

    end

        for j=1:1:i

            fprintf('\t');

            fprintf('*');

        end

            fprintf('\n');

end


Sample Input and Output

>> rightangledtriangle_4(5)

                                *             *             *             *             *

                                               *             *             *             *

                                                              *             *             *

                                                                             *             *

                                                                                            *

>> rightangledtriangle_4(9)

                            *             *             *             *             *             *             *             *             *

                                            *            *             *             *             *             *             *             *

                                                           *            *             *             *             *             *             *

                                                                         *             *             *             *             *             *

                                                                                        *             *             *             *             *

                                                                                                       *             *             *             *

                                                                                                                       *             *             *

                                                                                                                                      *             *

                                                                                                                                                     *

           



No comments

Popular Posts

Followers