50 likes | 208 Views
Binomial expansion. Introduction to Computers and Programming, NCTU, Fall 2012. Functions. return-value-type function-name(parameter-list) { declarations and statements } return-value-type void, int , long, etc. parameter-list int a, int b, char ch , float f Examples:
E N D
Binomial expansion Introduction to Computers and Programming, NCTU, Fall 2012
Functions return-value-type function-name(parameter-list) { declarations and statements } • return-value-type void, int, long, etc. • parameter-list int a, int b, char ch, float f • Examples: intmain() {…} long factorial(int n) {…} double result(double base, boolisFast, double interest) {…}
Binomial expansion (x + y)3 = x3 + 3x2y + 3xy2 + y3 (x + y)4 = x4 + 4x3y + 6x2y2 + 4xy3 + y4 So, the binomial coefficients for power of 3 are 1, 3, 3, 1;and for power of 4: 1, 4, 6, 4, 1 There exists a recursive formula to compute them: With initial conditions
Practice • Input: n • Output: binomial coefficients for power expansion of n • Exit if n = -1 • Hint: use recursion