Ticker

6/recent/ticker-posts

Reverse Star Pattern with Solution




Reverse Star Pattern:

Problem Description:

You're given a number N. Print the first N lines of the below-given pattern.


                *

               **

              ***

             ****

            *****

Input:

·       First-line will contain the number N.

Output:

Print the first N lines of the given pattern.

Constraints

·       1≤N≤200

Sample Input 1:

            4

Sample Output 1:

               *

              **

             ***

            ****

Sample Input 2:

            2

Sample Output 2:

             *

            **

EXPLANATION:

·       In the first example, we'll print the first 4 lines of the given pattern.

·       In the second example, we'll print the first 2 lines of the given pattern

Solution:

C++:

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 1i <= ni++)
    {
        int j;
        for (j = 1j <= n - ij++)
            cout << " ";
        for (jj <= nj++)
            cout << "*";
        cout << endl;
    }
    return 0;
}



Don't forget to subscribe and share this post.

Post a Comment

0 Comments