Feb 19, 2010 at 1:39am UTC
Thanks. I got it, fixed.
Last edited on Feb 22, 2010 at 5:23am UTC
Feb 19, 2010 at 1:45am UTC
1 2 3 4 5 6 7 8 9 10
int i, j;
for (i = 1; i <= 9; i++)
{
for (j = 1; j <= (9 - i); j++)
cout<<" " ;
for (j = 1; j <= i; j++)
cout<<setw(1)<<j;
for (j = (i - 1); j >= 1; j--)
cout<<setw(1)<<j;
}
Last edited on Feb 19, 2010 at 1:47am UTC
Feb 20, 2010 at 10:53pm UTC
your program does not run.
Last edited on Feb 22, 2010 at 6:04am UTC
Feb 21, 2010 at 1:40am UTC
Done.
Last edited on Feb 22, 2010 at 5:43am UTC
Feb 21, 2010 at 1:44am UTC
i intentionally did it to be a fix size, for you to work the rest out..
it's very easy to modify it from there, come on try it..
Feb 21, 2010 at 1:47am UTC
Think about the logic.
- You need to draw X rows, where X is the number input by the user.
- Each row has columns which count down from X to 1, then count back up to X
- Each column contains either a number, or spaces
-- ask yourself: what determines whether or not the column contains a space or a number?
Here's a push to get you started:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
for ( rows )
{
for ( count_down_columns )
{
if ( I_print_a_number_here )
print_a_number;
else
print_some_spaces;
}
for ( count_up_columns )
{
...
}
}
EDIT:
or yeah you could do what blackcoder was suggesting. His is probably a little more efficient actually. Heh.
Last edited on Feb 21, 2010 at 1:48am UTC
Feb 21, 2010 at 1:59am UTC
Thanks.
Last edited on Feb 22, 2010 at 5:47am UTC
Feb 21, 2010 at 2:00am UTC
can post a better code Disch? i'd love to see something more efficient?
note: im not starting a competition, just want to see your style.. how others solve it..
Feb 21, 2010 at 2:06am UTC
ok you want your code
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
#include <iostream>
using namespace std;
//miss spelled here
int main() {
int usernum; // inputted from user size of pyramid
// error checking-value must be from 1-15
do {
cout << "Enter an integer from 1-15: " ;
cin >> usernum;
} while (usernum < 1 || usernum > 15);
for (int rownum = 1; rownum <= usernum; rownum ++ ) {
for (int spacenum = 1; spacenum <= (usernum - rownum)* 2; spacenum ++)
cout << " " ;
for (int colnum1 = rownum; colnum1 >= 1; colnum1 --) { //<- adds a bracket
cout << colnum1 << " " ;
if (colnum1 < 10)
cout << " " ;
} //<- adds a bracket
//miss spelled here
for (int colnum2 = 2; colnum2 <= rownum; colnum2 ++)
cout << colnum2 << " " ;
cout <<endl;
}
return 0;
}
Last edited on Feb 21, 2010 at 2:07am UTC