You are on page 1of 3

Practical 02

Aim:- To write a recursive program to find the factorial of a number

Description:- Recurrence relation to find the factorial of a number is

F(n)= n*F(n-1)

Time complexity:-
T(0)=1

T(1)=1

T(n)= T(n-1)+3

T(n)=T(n-2)+6

T(n)=T(n-k)+3k

When k=n , T(n)=T(n-n)+3n= 1+3n = O(n)

C Program:-

#include<stdio.h>

#include<conio.h>

long int factorial(int);

int main()

int n;

printf("Program written by : Shashank Sharma (Roll no:- 1902031037) \n");

printf("Enter the number to find its factorial: \n");


scanf("%d",&n);

printf("%d is the factorial of number %d",factorial(n),n);

getch();

return 0;

long int factorial(int n)

if(n<=1)

return 1;

else

return n*factorial(n-1);

Output:-

You might also like