C program to find factorial using recursion

Program:

#include <stdio.h>


int fact(int n);


void main()

{

    int factorial, num=5;

    

    factorial = fact(num);

    

    printf("factorial = %d",factorial);

}


int fact(int n)

{

    if(n==0 || n==1)

        return 1;

    else

        return n*fact(n-1);

}


Output:

factorial = 120


Drafted on 🌏 by,

Jal


peace

Comments

Popular posts from this blog

C program to read and display book information using structure

Count positive, negative and zero values in an array

Maximum value from array