Qbasicnews.com

Full Version: Pascal triangle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how can you tablulate up pascals triangle and print it out in triangle form.

so far i got use LOCATE to center it and print.
FOR loops to print and ad up numbers
DIM to make some arrays to hold the values
Code:
x = (80 - LEN(STR$(number))) \ 2

LOCATE row, x
I'm not sure if that's right, but it seems LOCATE is the only way to do it.
not necessarily, you can always use the text buffer to print it character by character. but locate's just easier Smile
Just to add. Using str$ on an integer puts a space infront of the char. So when you use Str$ always use ltrim$ to remove the space.

eg:

Num% = 1337

x = 40 - INT(LEN(LTRIM$(STR$(Num%))) / 2)

Locate row, x: PRINT Num%
it doesnt always put a space, but it reserves a space for a minus sign. if you input a negative number it's not going to leave a space, hence why you use ltrim$ and not mid$.