A row of Pascal's triangle · صف من مثلث باسكال
A row of Pascal's triangle
Every number in Pascal's triangle is the sum of the two numbers just above it, and every row starts and ends with 1.
Build the rows one at a time. A new row starts with 1, then adds each neighbouring pair of the previous row, row[i] + row[i + 1], and ends with 1. After n rounds, row is the answer. In China the same triangle is named after Yang Hui, who described it in 1261.
صف من مثلث باسكال
كل عدد في مثلث باسكال هو مجموع العددين اللذين يقعان مباشرة فوقه، وكل صف يبدأ وينتهي بـ 1.
بني الصفوف واحداً تلو الآخر. يبدأ الصف الجديد بـ 1، ثم يضيف كل زوج مجاور من الصف السابق، row[i] + row[i + 1]، وينتهي بـ 1. بعد n جولات، row هو الجواب. في الصين يُسمى نفس المثلث باسم يانغ هوي، الذي وصفه عام 1261.
Write pascal_row(n) that returns row n of Pascal's triangle, counting the top row [1] as row 0. Row 4 is [1, 4, 6, 4, 1]. · اكتب pascal_row(n) تُرجع الصف n من مثلث باسكال، مع اعتبار الصف العلوي [1] هو الصف 0. الصف 4 هو [1, 4, 6, 4, 1].
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.