Hello you guys, Would anyone like to give me suggestions on how to make a code for the following pattern? Please note that the numbers arent part of the pattern, they are just a guide for row and column.

*  *  *  *  *  # # #          1
*  *  *  *  # # # #          2             [B] ROW  [/B] 
*  *  *  # # # # #          3

1  2  3  4  5  6 7 8  
     [B]COL[/B]

Its a 3 x 8 box, the sides represents the rows and the top part of the pattern is the columns. I tried doing the folowing code but it didnt work:

let i =row and j=column

for (i=1; i <= 3; ++i) {
     for (j=5; j >= 1; --j) {
        printf("*");
    }
     for( j=4;j <= 8;++i) {
       printf("#");
     }

Any suggestions????

* * * * * # # # 1
* * * * # # # # 2 ROW 
* * * # # # # # 3

realize that there are 5 '*' the 4 '*' then 3 '*' after each line.
On the other side, there are 3 '#', then 4 '#' then 5 '#'.

What does this tell you about where to start and end for each symbols.

* * * * * # # # 1
* * * * # # # # 2 ROW 
* * * # # # # # 3

realize that there are 5 '*' the 4 '*' then 3 '*' after each line.
On the other side, there are 3 '#', then 4 '#' then 5 '#'.

What does this tell you about where to start and end for each symbols.

It means that i should start from column 5 and somehow subtract 1 until i get to column 3 but at the same time it should go from row 1 to row 3. For the right side it would be similar but the column should start at 6th column (3'#') and end at the 4th column. But in both cases row is:
for (row=1;row <= 3;row++) right?? So should i have two nested loops inside the general loop that will determine the iterations of the program??

So by now you should know that you need nested loop, right?
since there are 3 rows, your outer loop should go up to 3.

Now for your nested loop. What you can have is have 2 for loop inside the
first loop. One loop prints out '*' starting from 5 to 3 and Another loop
starting from 3 to 5 that prints out '#'.

Here is what your for loop might look like :

const int N_ROW = 3;
for(int i = 0; i < N_ROW; i++) 
{
    for(int j = 5; j > =3 ; --j){ /*do something here */ }
    for(int k = 3; k <= 5; k++) { /*do something here */ }
  
    cout << endl; //because its the end of the row
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.