+ 1
******** *** *** ** ** * *
wap to print following pattern
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
+ 2
@Zeke: it's still a regular pattern, just that the middle space count starts at 0.
+ 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;
}
+ 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
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...
- 2
just do it