Chapter 5 Code
Chapter 5 Code
(Basic to Advanced)
Topics to be covered :
Installation + Setup
Chapter 1 - Variables, Data types + Input/Output
Chapter 2 - Instructions & Operators
Chapter 3 - Conditional Statements
Chapter 4 - Loop Control Statements
Chapter 5 - Functions & Recursion
Chapter 6 - Pointers
Chapter 7 - Arrays
Chapter 8 - Strings
Chapter 9 - Structures
Chapter 10 - File I/O
Chapter 11 - Dynamic Memory Allocation
//function declaration/prototype
void printHello();
int main() {
//function call
printHello();
return 0;
}
//function definition
void printHello() {
printf("Hello!\n");
}
int main() {
int n;
printf("enter n : ");
scanf("%d", &n);
printf("square is : %d", calcSquare(n));
return 0;
}
int calcSquare(int n) {
return n * n;
}
# include <stdio.h>
//function to print factorial of n
int factorial(int n);
int main() {
int n;
printf("enter n : ");
scanf("%d", &n);
printf("factorial is : %d", factorial(n));
return 0;
}
int factorial(int n) {
if(n == 0) {
return 1;
}
int factnm1 = factorial(n-1);
int factn = factnm1 * n;
return factn;
}