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!
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).
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!
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
}