BlueBook

p183ex6 - Pascal's Triangle

Given an integer N, output the first N rows of Pascal's triangle.

Input

A single integer N (1 ≤ N ≤ 20).

Output

The first N rows of Pascal's triangle, in order from top to bottom. Each row should be printed in a separate line, and the entries in each row should be printed from left to right with exactly one space between each pair of horizontally adjacent entries.

Sample Input

3

Sample Output

1
1 1
1 2 1

All Submissions
Best Solutions


Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 25, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

is bruteforce accepted for this problem?

I think you misunderstand what brute force means.

Anyway: so long as you're not doing anything that's clearly cheating, e.g. copying code or hardcoding the output, you can do more or less whatever you want.

Wait, hardcoding is cheating ?????

Well, it depends on the scale.

If you hardcode output based on the test input because you have prior knowledge of the test cases, then yes, that's cheating.

If a problem has only a possible inputs and you precompute the answers to all of them, so your program is effectively cin >> input; cout << answer[input];, then that's a bit borderline. I mean, if your precomputation program takes 2 days and 3 GB of memory to run, then you basically just ignored the time and memory limits, so I would personally consider it cheating.

If, however, a problem has only five possible inputs, and solving each instance takes only a few seconds of human thought (so microseconds of CPU time), then that's completely legitimate.

Basically, if it seems like it's cheating, it's probably cheating. If it doesn't, then it's probably fine.

I thought it was like 1 2 3 2 1 but it's much harder! Can someone help me with my code? How would i get the numbers i output?

I suggest you do some reading on Pascal's Triangle. In fact, just go read the Wikipedia article.

I know i saw but could you help me with how to do it?

Use a two-dimensional array.

Is it the same as like:
var
a:array [1..s] of integer?

var
a:array [1..10,1..20] of integer;

a[8,19]=5;

A 2D array is like an array of arrays. If a 1D array is like a line of variables, think of a 2D array as a grid.

wow i seriously do not get this how do i make the output of lines 18, 19, and 20 on one line? or is this not possible on pascal?

I'm not sure, but taking out the uses crt, clrscr, etc. should fix it.