samedi 24 avril 2021

triangle side by side in C++

i wrote this code

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=2*n+1;j++)
            if(j>=n-i+2&&j<=n+i)
                cout<<'*';
            else
                cout<<' ';
        cout<<endl;

    }
}

And now I want to control how many triangles are side by side to each other, how can I do that?

For example when i choose 3 triangles with 5 rows and output this

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

And i choose 2 or 4 triangles or more with optional rows like that output the triangles printed side by side Thank you.

Aucun commentaire:

Enregistrer un commentaire