-1

I want to make a triangle with this pattern:

1
11
111

then repeat the last row as much as how many rows in it:

1
11
111
111
111
111

I already made code for the triangle pattern, but I'm stuck on looping the last row. Here's my code:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
    int rows;
    cin>>rows;

    for(int i=1;i<=rows;i++){
        for (int j = 1; j <= i; j++)
        {
            cout<<"1";
        }
        cout<<endl;
    }
    return 0;
}

thanks

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Robby
  • 33
  • 2
  • Obligatory https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice and https://stackoverflow.com/questions/8311058/n-or-n-or-stdendl-to-stdcout?noredirect=1&lq=1 – SuperStormer Dec 11 '21 at 23:58
  • 2
    The part you want to add is just like the triangle, but every row is the same length. The code should reflect this. – Scott Hunter Dec 11 '21 at 23:58
  • 1
    Hint: One way to do it is to make a *new* `for` loop inside your main function, after the end of your first `for` loop. – David Grayson Dec 12 '21 at 00:02
  • 1
    Instead of making another loop you could just use `std::min()` in a strategic place. – Dietmar Kühl Dec 12 '21 at 00:10

1 Answers1

1

I already found a way to do it, I add a new for loop after my first loop and it works :D

here's the code

    for(int l=1;l<=rows;l++){
    for(int k=1;k<=rows;k++){
        cout<<"1";
    }
    cout<<endl;
    }
    return 0;
}

Thank you so much!

Robby
  • 33
  • 2