+ 1

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

wap to print following pattern

23rd Oct 2016, 4:00 PM
Akshay Kevat
Akshay Kevat - avatar
6 Réponses
+ 2
for (int i = 0; i < 7; i++) { if (i == 0) { for (int j = 0; j < 8; j++) { cout << "*"; } if (i == 1) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { cout << "*"; } cout << endl; } } you get the picture. You could also do it with a switch, or even way for elegant for loop, if those eight stars on the left had a space in the middle of them; then it would be an actual pattern
24th Oct 2016, 2:01 AM
Zeke Williams
Zeke Williams - avatar
+ 2
@Zeke: it's still a regular pattern, just that the middle space count starts at 0.
24th Oct 2016, 9:19 PM
Liam
Liam - avatar
+ 2
Split it into 3 sections: stars on the left, spaces in the middle and the stars on the right. The star count (on both sides) is the total number of rows minus the current row in the loop, the space count in the middle is the is current or in the loop multiplied by 2. int numberOfRows = 4; for (int row = 0; row < numberOfRows; row++) { for (int i = 0; i < numberOfRows - row; i++) { cout << "*"; } for (int i = 0; i < row * 2; i++) { cout << " "; } for (int i = 0; i < numberOfRows - row; i++) { cout << "*"; } cout << endl; }
24th Oct 2016, 9:20 PM
Liam
Liam - avatar
+ 1
I'm sorry, on a laptop your pattern didn't totally show up using solo's website! All I saw was this: ******** *** *** ** ** * * haha oops
24th Oct 2016, 11:26 PM
Zeke Williams
Zeke Williams - avatar
0
Yeah, the website formatting is off for me too. Pretty annoying when you try to copy/paste code from it - it all ends up being on one line...
26th Oct 2016, 7:38 PM
Liam
Liam - avatar
- 2
just do it
23rd Oct 2016, 8:45 PM
nekogami
nekogami - avatar