50 likes | 226 Vues
This introduction covers the concepts of binomial expansion and the implementation of recursive functions in programming. It highlights the structure of functions, including return value types and parameter lists, with examples like calculating factorials and handling double results. The binomial expansion (x+y)^3 and (x+y)^4 are explored, showing how to derive binomial coefficients, which are essential for polynomial expansions. A practical exercise is provided, aimed at computing binomial coefficients recursively based on user input.
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