Lab 4: Functions & Recursion
Objectives:
● To understand user-defined functions in C
● To understand function declaration, definition, and calling
● To understand recursion and recursive problem solving
Theory:
● Functions
● Types of Functions in C
● Components of a Function
● Recursion
Problem:
<Question Here>
Problem Analysis:
<Describe what the problem is about, and how you plan to solve it>
Input Variable(s) Processing Output Variable(s) Necessary Header files/
Variables/Calculations functions
Algorithm:
<Algorithm Here>
Flow Chart:
<Flowchart Here>
Source Code:
<Your source code here>
Output (Compilation, Debugging & Testing):
<Your O/P here>
Discussion
<Discussion here>
Conclusion
<Conclusion here>
Lab Exercise:
1. Write a program to add, subtract, multiply, and divide two integers using a user-defined
function with return type.
2. Write a program to calculate the sum of the first n natural numbers using a recursive
function.
3. Define a function named fact() to calculate the factorial of a number n, and then write a
program that uses this function fact() to calculate combination and permutation.
4. Write a recursive function to generate the Fibonacci series.
5. Write a program that illustrates the use of local, global, and static variables.
Home Assignment:
1. Write a program using user-defined functions with return type to check whether a given
number is a palindrome.