Recursion
Problem Set 7.1: Recursion (Class)
- Printing Series - Print Hello World N Times 
- 1, 2, 3, 4, ⋯⋯⋯, N 
- 1, 3, 5, 7, ⋯⋯⋯, 99 
- 2, 4, 6, 8, ⋯⋯⋯, N 
- N, N-1, N-2, …, 3, 2, 1 
- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ⋯⋯⋯, N (Calculate the Fibonacci series up to Nth term or up to N using recursion) 
 
- Summation of Series - 1 + 2 + 3 + 4 + ⋯⋯ + N 
- 1 + 3 + 5 + 7 + ⋯⋯⋯ + N 
- 2 + 4 + 6 + 8 + ⋯⋯⋯ + N 
- 1^2 + 3^2 + 5^2 + 7^2 + ⋯⋯⋯ + (101)^2 
- 2^3 + 4^3 + 6^3 + 8^3 + ⋯⋯⋯ + N^3 
- N! = 1 * 2 * 3 * 4 * ⋯⋯⋯ * N 
 
- Array - Define a recursive function that takes an integer array as an argument and prints the array elements. 
- Define a recursive function that takes an integer array as an argument and prints the array elements in reverse order. 
- Reverse the array 
- Implement Linear Search using recursion 
- Implement Binary Search using recursion 
- Search an element (Key, Maximum, Minimum, Second Maximum, and Second Minimum) in an array using recursion - Find the Key Value that exists or not in an array using recursion (Return true or false) 
- Find the Key Value that exists or not in an array using recursion (Return the index if found otherwise return -1) 
- Find the minimum number from an array using recursion 
- Find the maximum number from an array using recursion 
- Find the minimum number from an array using recursion 
 
- Print Array elements in pairs of first and last elements and so on 
 
- Others - Implement Euclidean Algorithm to Calculate Greatest Common Divisor (GCD) using recursion 
- Least Common Multiple (LCM) 
- Palindrome Checker 
- Print an Integer in reverse order using recursion 
- Print String using recursion 
- Print String in reverse order using recursion 
- Reverse String using recursion 
- Tower of Hanoi 
- Calculate a^b using recursion 
- Calculate a^b % c using recursion 
- Calculate sqrt(a) using recursion 
- Base Conversion - Decimal to Binary 
- Binary to Decimal 
- Decimal to Octal 
- Decimal to Hexadecimal 
- Decimal to Base N Number 
- Octal to Decimal 
- Hexadecimal to Decimal 
- Base N Number to Decimal 
 
 
Exercise: 
#include<stdio.h>
int fib(int n);
int main(){
    int n = 6;
    for(int i=1; i<10; i++)
        printf("%d\n",fib(i));
    return 0;
}
int fib(int n){
    if(n<=2) return 1;
    return  fib(n-2) + fib(n-1);
}#include<stdio.h>
int bigmod(int a, int b, int m);
int main(){
    int a = 5, b = 15, m = 6;
    printf("%d\n", bigmod(a, b, m));
    return 0;
}
int bigmod(int a, int b, int m){
    int x;
    if(b==0){
        return 1;
    }
    if(b%2==1){
        x = bigmod(a, b-1, m);
        return (a*x) % m;
    }else{
        int x = bigmod(a, b/2, m);
        return (x*x) % m;
    }
}
Last updated