As described in Wikipedia, Pascal's triangle is a triangular array of the binomial coefficients. The element k on row n of Pascal’s triangle can be calculated by the following relation:
C(n, 1) = 1, for n = 1, 2, …
C(n, n) = 1, for n = 1, 2, …
C(n, k) = C(n-1, k-1) + C(n-1, k), for k = 2, 3, … and for n = 2, 3, …
Note that
1. This problem involves three files.
You will be provided with main.cpp and function.h, and asked to implement function.cpp.
2. For OJ submission:
Step 1. Submit only your function.cpp into the submission block. (Please choose c++ compiler)
Step 2. Check the results and debug your program if necessary.
main.cpp
#include <stdio.h>
#include "function.h"
int main()
{
int n = -1;
while(n!=0){
scanf("%d",&n);
pascalNum(n);
}
return 0;
}
function.h
void pascalNum(int n);
A positive integer M (1<=M<=10), if input is 0 then exit the while loop and exit the program.
Print some space so that the output number is that we know the Pascal's triangle number and use %6d to print each element. And there is a ‘\n’ at the end of each line except input is 0.