# C Programming

## C Recursive Functions

- Recursion is a process by which a function calls itself repeatedly, until some specified condition has been satisfied.
- The process is used for repetitive computations in which each action is stated in terms of a previous result.
- In order to solve a problem recursively, two conditions must be satisfied.
- First, the problem must be written in a recursive form, and second, the problem statement must include a stopping condition

##### Example:

**Suppose, for example, we wish to calculate the factorial of a positive integer quantity.**

We would normally express this problem as:

** ****n! = 1 × 2 × 3 × . . . . × n**

where n is the specified positive integer

However, we can also express this problem in another way by writing:

**n! = n × ( n – 1 ) !**

- This is a recursive statement of the problem, in which the desired action ( the calculation of n!) is expressed in terms of a previous result [ the value of ( n-1 )!, which is assumed to be known].
- Also, we know that 1! = 1, by definition.
- This last expression provides a stopping condition for the
*recursion.*

##### Calculating Factorial Using Recursion

# include <stdio.h> long int factorial ( int n) { if ( n <= 1) return 1; else return ( n * factorial ( n – 1 )); } void main ( void ) { printf ( “\n 5! = %ld”, factorial(5)); }

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.

C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs, and used to re-implement the Unix operating system. It has since become one of the most widely used programming languages of all time, with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by the American National Standards Institute (ANSI) since 1989 and subsequently by the International Organization for Standardization (ISO).

### Course Features

- Lectures 19
- Quizzes 0
- Duration 50 hours
- Skill level All levels
- Language English
- Students 2
- Certificate No
- Assessments Self