Ladderophilia

Aditya is fond of ladders. Every day he goes through pictures of ladders online but unfortunately today he ran out of ladder pictures online. Write a program to print “ladder with N steps”, which he can use to get his daily dose of ladder love.

Example:

Input:  n = 4

Output

* * * * ***** * * * * ***** * * * * ***** * * * * ***** * * * *

Approach:

C++

#include <bits/stdc++.h>
using namespace std;

void ladderOphilia(int n)
{
    int m = n + (n + 1) * 2;
    int l = 2;
    for (int i = 0i < mi++)
    {
        if (i == l)
        {
            cout << "*****\n";
            l = l + 3;
        }
        else
            cout << "*   *\n";
    }
}
int main()
{
    int n = 4;

    ladderOphilia(n);

    return 0;
}


No comments:

Post a Comment