Pascal's triangle 2d array - formatting printed output

前端 未结 2 1940
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 20:03

I have a small assignment where I have to use a 2d array to produce Pascal\'s triangle. Here is my code, and it works. there is an extra credit opportunity if I display the

2条回答
  •  旧巷少年郎
    2020-12-10 20:25

    You're encountering spacing issues because you need to add whitespace to certain numbers to accommodate space that larger numbers occupy. First determine what the largest number you plan to print is (programmatically). Then determine the number of digits in that number log(n). You can then use this number to print whitespace for numbers that have less digits than your largest number to make your printing look nicer.

提交回复
热议问题