problem with 2 particular outputs

Hello,

i tried writing a program for two particular outputs but i dont get them after trying them a lot. The two Outputs are given below. Also please tell me the logic behind it and how to do its programming.
I would really appreciate your time and hope that this comes out well!

1)

   &  &  &  &  &  &  &     
      &  &  &  &  &
         &  &  &
            &
          


and
2)

                & 
              &   &  
            &       &
          &           &
        &               &
      & & & & & & & & & & &        
  


Are you able to at least do
&&&&&&&
&&&&&
&&&
&
?

Regardless, the logic is to count the logic of spaces and symbols on each line and see how those are related to line numbers. Often it may be good to separate the shape into several parts (for the second one, you may want to print the first line, the last one and all the rest in three parts of code).

&&&&&&&     
&&&&&
&&&
&


ya i got that one correctly and another one which is verticall opposite

&
&&
&&&
&&&&
&&&&&       


But the quest. arises for the other 2! i also managed to get this diagram but cant figure out anything further on it .....



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

I would use a 2d array with nested for loops.

The array would act almost like a grid, with x and y values. You could then populate the array with a value wherever you want a * to appear. Then, have if statements that output a * if they find that value.
Like I said, you need to see a pattern. All of them are really the same..
I'll do the first one for you. nth line, where n starts from 0, has (n+1) times " " and then (7-2*n) times "& " and finally a "\n". To repeat some string several times, you need a for loop. You are going to need three for loops: two for the different strings and one for all the lines.
iHutch & hamsterman- i didnt quite really understand you there. The thing is that i need to get the particular output using only loops. Right now I am trying it with for() loop but i dont get my desired output.

Also i thought of this but cant figure the programming part of it. What if I use a loop for the spaces. But i cant really figure that part out!

Pls help.
Okay then, I guess I'll have to literary do one for you..
1
2
3
4
5
for(int line = 0; line < 4; line++) {//one for loop to go through all the lines
   for(int i = 0; i < line+1; i++) std::cout << "   ";//a for loop that prints "   " (line+1) times
   for(int i = 0; i < 7-2*line; i++) std::cout << "&  ";//prints "&  " (7-2*line) times
   std::cout << '\n';//goes to a new line
}
Topic archived. No new replies allowed.