Pascal's Triangle: Warm-up
Lesson 2 of 3 in Coddy's Interview Coding Challenges - Pack VI course.
Pascal's Triangle is a triangular array of numbers where each number is the sum of the two numbers directly above it.
The first row contains the number 1, and each subsequent row begins and ends with 1. Pascal's Triangle has many mathematical and combinatorial applications, including calculating binomial coefficients and probabilities.
Pascal's Triangle of size 5,
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1Challenge
MediumWrite a function pascal that gets an integer n and outputs a string which represents two dimensional array pascal's triangle of size n.
Examples,
Input: 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Input: 3
Output: [[1],[1,1],[1,2,1]]
Emit any spaces in your output!
Try it yourself
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* pascal(int n) {
// Write code here
}