Feb 7, 2012 at 11:14pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
// HW 5.12b Write a program that displays the following
// **********
// *********
// ********
// *******
// ******
// *****
// ****
// ***
// **
// *
#include <iostream>
using namespace std;
int main()
{
for (int k =1; k > 0; --k){
for ( int i = 10;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 9;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 8;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 7;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 6;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 5;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 4;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 3;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 2;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
for ( int i = 1;i > 0; --i ){
cout << "*" ;
}
for ( int j = 1;j > 0; --j ){
cout << "\n" ;
}
}
}// main
The problem states that cout must be written like this
cout "*" ;
and that nested for statements must be used.
Last edited on Feb 7, 2012 at 11:16pm UTC
Feb 7, 2012 at 11:30pm UTC
What is the point of the outer loop across k if you never use the value of k? Since k has the values that you are hard coding to start off i and j (why are you alternating??) then you should use k:
for k across 10 to 1:
for i across 0 to k:
print *
print new line
Last edited on Feb 7, 2012 at 11:38pm UTC
Feb 7, 2012 at 11:33pm UTC
10 rows, maximum 10 cols.
Row 1 would get 10 cols.
Row 2 would get 9 cols.
Row 3 would get 8 cols.
.
.
.
.
row 10(this does not have to be zero indexed) would get 1 cols.
Are you seeing a pattern? The row should have an effect on the number of columns.
Feb 7, 2012 at 11:35pm UTC
I couldn't get it to start a new line and create the pattern without alternating "/n" and "*"
Feb 7, 2012 at 11:38pm UTC
Edited my post with something to help you.
Feb 7, 2012 at 11:39pm UTC
Create your algorithm on paper. I think you'll find it's much simpler than you think
Feb 8, 2012 at 12:31am UTC
I don't get it. Each time i runs through it executes j and then j runs through it's entire sequence. The best I can get it to do is print a 10x10 square of asterisks
Feb 9, 2012 at 4:00am UTC
Weird, I'm not seeing the value of j = (0+i), since 0 + i = i, regardless.