In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
void recursion() {
   recursion(); /* function calls itself */
}

int main() {
   recursion();
}  
   #include <stdio.h
unsigned long long int factorial(unsigned int i) {

   if(i <= 1) {
      return 1;
   }
   return i * factorial(i - 1);
}

int  main() {
   int i = 12;
   printf("Factorial of %d is %d\n", i, factorial(i));
   return 0;
}
When the above code is compiled and executed, it produces the following result −
Factorial of 12 is 479001600

C Function

Display all prime numbers between two Intervals
Check Prime and Armstrong Number by making function
Check whether a number can be expressed as the sum of two prime number
Find sum of natural numbers using recursion
Calculate factorial of a number using recursion
Find G.C.D using recursion
Reverse a sentence using recursion
Calculate the power of a number using recursion
Convert binary number to decimal and vice-versa
Convert octal Number to decimal and vice-versa
Convert binary number to octal and vice-versa

Example 1: Prime Numbers Between Two Integers

#include <stdio.h>

int checkPrimeNumber(int n);
int main()
{
    int n1, n2, i, flag;

    printf("Enter two positive integers: ");
    scanf("%d %d", &n1, &n2);
    printf("Prime numbers between %d and %d are: ", n1, n2);

    for(i=n1+1; i<n2; ++i)
    {
        // i is a prime number, flag will be equal to 1
        flag = checkPrimeNumber(i);

        if(flag == 1)
            printf("%d ",i);
    }
    return 0;
}

// user-defined function to check prime number
int checkPrimeNumber(int n)
{
    int j, flag = 1;

    for(j=2; j <= n/2; ++j)
    {
        if (n%j == 0)
        {
            flag =0;
            break;
        }
    }
    return flag;
}
Output
Enter two positive integers: 12
30
Prime numbers between 12 and 30 are: 13 17 19 23 29

Example 3: Check Prime and Armstrong Number

#include <stdio.h>
#include <math.h>

int checkPrimeNumber(int n);
int checkArmstrongNumber(int n);

int main()
{
    int n, flag;

    printf("Enter a positive integer: ");
    scanf("%d", &n);

    // Check prime number
    flag = checkPrimeNumber(n);
    if (flag == 1)
        printf("%d is a prime number.\n", n);
    else
        printf("%d is not a prime number.\n", n);

    // Check Armstrong number
    flag = checkArmstrongNumber(n);
    if (flag == 1)
        printf("%d is an Armstrong number.", n);
    else
        printf("%d is not an Armstrong number.",n);
    return 0;
}

int checkPrimeNumber(int n)
{
    int i, flag = 1;

    for(i=2; i<=n/2; ++i)
    {

    // condition for non-prime number
        if(n%i == 0)
        {
            flag = 0;
            break;
        }
    }
    return flag;
}

int checkArmstrongNumber(int number)
{
    int originalNumber, remainder, result = 0, n = 0, flag;

    originalNumber = number;

    while (originalNumber != 0)
    {
        originalNumber /= 10;
        ++n;
    }

    originalNumber = number;

    while (originalNumber != 0)
    {
        remainder = originalNumber%10;
        result += pow(remainder, n);
        originalNumber /= 10;
    }

    // condition for Armstrong number
    if(result == number)
        flag = 1;
    else
        flag = 0;

    return flag;
}
Output
Enter a positive integer: 407
407 is not a prime number.
407 is an Armstrong number.

Example 1: Program to convert binary number to decimal

#include <stdio.h>
#include <math.h>
int convertBinaryToDecimal(long long n);

int main()
{
    long long n;
    printf("Enter a binary number: ");
    scanf("%lld", &n);
    printf("%lld in binary = %d in decimal", n, convertBinaryToDecimal(n));
    return 0;
}

int convertBinaryToDecimal(long long n)
{
    int decimalNumber = 0, i = 0, remainder;
    while (n!=0)
    {
        remainder = n%10;
        n /= 10;
        decimalNumber += remainder*pow(2,i);
        ++i;
    }
    return decimalNumber;
}
Output
Enter a binary number: 110110111
110110111 in binary = 439
Question 1
Output of following program?
#include <stdio.h>
int main()
{
    int i = 5;
    printf("%d %d %d", i++, i++, i++);
    return 0;
}
A
7 6 5
B
5 6 7
C
7 7 7
D
Compiler Dependent

Question 2
In C, parameters are always
A
Passed by value
B
Passed by reference
C
Non-pointer variables are passed by value and pointers are passed by reference
D
Passed by value result

Question 3
Which of the following is true about return type of functions in C?
A
Functions can return any type
B
Functions can return any type except array and functions
C
Functions can return any type except array, functions and union
D
Functions can return any type except array, functions, function pointer and union
Question 4
#include <stdio.h>
int main()
{
  printf("%d", main); 
  return 0;
}
A
Address of main function
B
Compiler Error
C
Runtime Error
D
Some random value
Question 5
Output?
#include <stdio.h>
 
int main()
{
    int (*ptr)(int ) = fun;
    (*ptr)(3);
    return 0;
}
 
int fun(int n)
{
  for(;n > 0; n--)
    printf("GeeksQuiz ");
  return 0;
}
A
GeeksQuiz GeeksQuiz GeeksQuiz
B
GeeksQuiz GeeksQuiz
C
Compiler Error
D
Runtime Error


Question 6
Output of following program?
#include<stdio.h>
 
void dynamic(int s, ...)
{
    printf("%d ", s);
}
 
int main()
{
    dynamic(2, 4, 6, 8);
    dynamic(3, 6, 9);
    return 0;
}
A
2 3
B
Compiler Error
C
4 3
D
3 2

Question 7
Predict the output?
#include <stdio.h>
int main()
{
    void demo();
    void (*fun)();
    fun = demo;
    (*fun)();
    fun();
    return 0;
}
 
void demo()
{
    printf("GeeksQuiz ");
}
A
GeeksQuiz
B
GeeksQuiz GeeksQuiz
C
Compiler Error
D
Blank Screen
Question 8
What is the meaning of using extern before function declaration? For example following function sum is made extern
extern int sum(int x, int y, int z)
{
    return (x + y + z);
}
A
Function is made globally available
B
extern means nothing, sum() is same without extern keyword.
C
Function need not to be declared before its use
D
Function is made local to the file.

Question 9
What is the meaning of using static before function declaration? For example following function sum is made static
static int sum(int x, int y, int z)
{
    return (x + y + z);
}
A
Static means nothing, sum() is same without static keyword.
B
Function need not to be declared before its use
C
Access to static functions is restricted to the file where they are declared
D
Static functions are made inline
 


Question 10
In C, what is the meaning of following function prototype with empty parameter list
void fun()
{
   /* .... */
}
A
Function can only be called without any parameter
B
Function can be called with any number of parameters of any types
C
Function can be called with any number of integer parameters.
D
Function can be called with one integer parameter