[CHALLANGE] Pascal Triangle | Sololearn: Learn to code for FREE!


[CHALLANGE] Pascal Triangle

Input(number of rows) = 6 output: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Create a program which will make such triangle 1>Using Arrays 2>Without using Arrays Good Luck :)

10/29/2017 10:38:19 AM

Mr. Bot

14 Answers

New Answer


My two solutions. The two versions use the same formatting which allows for only 3 digit numbers and therefore loses its neatness when n exceeds 12. It still works. Using an array: https://code.sololearn.com/cBXDN7k81y0B/#java Without using an array. https://code.sololearn.com/c2l37lxXhPfr/#java


here is my try // using both arrays and loops ☺ https://code.sololearn.com/c5g3Qt9Lqt5e/?ref=app




two lines ... lazy https://code.sololearn.com/cVifR0ybhcNu/?ref=app


My try, without arrays https://code.sololearn.com/cGbf57Un3bXu/?ref=app


Javascript: https://code.sololearn.com/Wb4ZMiceHBs6/?ref=app


my java try https://code.sololearn.com/cGO8bXczaL6l/?ref=app


Here is mine using arrays: https://code.sololearn.com/cAuablJG3TRE




w/o arrays in c++ edit: w/ arrays in c++ edit: added a progarm with out using the x Choose y method. fixed both progarms, after re-reading challange. The Pascal Triangle row 0=1 and row 1 =1,1 yet the input is number of rows to print out including row 0, so I fixed my code to run the way the challange specified. https://code.sololearn.com/c2s4HEGHEX9S/?ref=app https://code.sololearn.com/c17F372suu6t/?ref=app https://code.sololearn.com/cvSEYEauGohr/?ref=app


for our webdesigner: if the even numbers get a different color the the odds... and the triangle is very big.... there is a wonderful pattern. for easiness dont print the numbers but different clored stars, depending on odd or even.


Happy New Year to all. Here is my try https://code.sololearn.com/cAGqE8084Fh9/?ref=app


Finally coded the non-array version. https://code.sololearn.com/c3b9ROBU06Z2/?ref=app


when building, two lists are used: 1 - previous half-line of the triangle 2 - current half-line of the triangle The values of the central snake axis of a triangle are always one first element of the list. Additionally, the power of two is calculated as the sum of the elements of the line of the triangle, but according to the list of the current semi-line. Additionally calculated https://code.sololearn.com/WHcElo6SdLdU/?ref=app