Hey I was having a major problem in creating a complex number pyramid. The user inputs a number of rows, but if it exceeds 20 it would go off page, so 1-20. I have a nested For loop (using QBasic) that looks something like this


for x = 1 to rows
for y = 1 to x
(CODE)
next y
(CODE)
next x

IT would be simple ... but the pyramid must look something like this

__________________0
_________________101
________________21012
_______________3210123

That would be for 4 rows, and it continues on in that pattern, with the last number increasing 1 per row....what ive come up with is creating a addition type formula, but i keep gettin the wrong solution and ive changed it about a million different ways so i scratched it all together..... :mad: lol, anyone have an idea on the coding ill need to create the 21012 type pattern in the second For loop....or am i setting it up completly wrong and need a new method of doing this??

Just a thought:

CLS
row = 0
For y = 0 to 19 ' 20 rows
   For x = 0 to row
       print "x" ' i cant remember the code for adjacent text
   Next
print " " 'new line
row = row + 1 ' increment row
Next

this should give you

0
01
012
0123
...

and im sure you can go back over the loop and draw the other side :)

First of all, you need a nonkerning font....

Second, I would use the concatenating + in an assignment statement to give you what you need, such as:

nu$ = STR$(i)
hol$ = nu$ + lis$ + nu$
lis$ = hol$

This adds the new number to both ends of the string lis$.

Now all you have to do is figure out how to use STRING$ to make a line of dashes, one dash shorter than the previous time.

Just a thought:

CLS
row = 0
For y = 0 to 19 ' 20 rows
   For x = 0 to row
       print "x" ' i cant remember the code for adjacent text
   Next
print " " 'new line
row = row + 1 ' increment row
Next

this should give you

0
01
012
0123
...

and im sure you can go back over the loop and draw the other side :)

To achieve the single line printing, please refer the below code. Hope this helps.....

Dim res As String
res = ""
row = 0
For y = 1 To 6 ' 20 rows
For x = 1 To row
res = res & "x"
Next
Print res
res = ""
row = row + 1 ' increment row
Next

Output will be as follows
x
xx
xxx
xxxx
xxxxx

Dim x As Long
Dim y As Long
Dim S As String
For y = 0 To 20
    S = ""
    For x = -y To y
        S = S & Abs(x)
    Next
    Print Space(100 - Len(S)) & S
Next
This article has been dead for over six months. Start a new discussion instead.