السابق التالي
0 / 33
الوحدة النمطية DEMO-32-60DEMO-C-32

Pascal's Triangle

DEMO-C-32 • Programming in C

Browser-only practice

بيان المشكلة

In this challenge, you will generate and print the first N rows of Pascal's Triangle.

What is Pascal's Triangle?

Pascal's Triangle is a triangular array of numbers where:

  • The first row contains only the number 1.
  • Each subsequent row begins and ends with 1, and each interior number is the sum of the two numbers directly above it from the previous row.


Your Task

Write a program that:

  • Reads an integer N from input.
  • Prints the first N rows of Pascal's Triangle.
  • Each row should contain numbers separated by spaces.
  • Each row should be printed on a new line.


Hint compute each value using the binomial coefficient formula:

value = value * (row - j) / (j + 1);


قيود

You must use nested loops to solve this problem. Do not use any built-in functions or libraries to generate the triangle directly.

تنسيق الإدخال

A single integer N (1 ≤ N ≤ 15), representing the number of rows to print.

تنسيق الإخراج

Print N lines, each representing a row of Pascal's Triangle. Numbers in each row should be separated by spaces.

حالات اختبار نموذجية

Submit runs every public testcase in this browser. Results and code never leave this device.

العينة رقم 1
عينة ظاهرة
3
1
1 1
1 2 1
Input: 3
العينة رقم 2
عينة ظاهرة
5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Input: 5
العينة رقم 3
عينة ظاهرة
1
1
Input: 1
العينة رقم 4
عينة ظاهرة
2
1
1 1
Input: 2

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
إعدادات المحرر