C11: Function Calls
Content |
-
Always make reasonable choices in your C program for your variable types.
-
Identifiers used in your implementation should be consistent with the pseudo-code.
-
In all examples the global variable is initialized with 5. But try different values:
-
Make sure you compute \(0!\) correct.
-
What do you noticw if \(n!\) is larger than \(255\)?
-
Exercise
Write a C program that realizes the following pseudo code:
Global variable: n = 5 Function factorial(n) result <- 1 for i = 2, ..., n result <- result * i Main program: return factorial(n)
Exercise
Write a C program that realizes the following pseudo code:
Global variable: n = 5 Function factorial(n) result <- 1 while n > 1 result <- result * n n <- n - 1 Main program: return factorial(n)
Exercise
Write a C program that realizes the following pseudo code:
Global variable: n = 5 Function factorial(n) if n > 1 return n*factorial(n-1) else return 1 Main program: return factorial(n)
Exercise
Make experiments with the handout examples.