Q1. Find the factorial of a given number using recursion

Generally these type of question ask, to check your knowledge of function recursion. Given below C program to find factorial of a given number.

 

#include<stdio.h>
int fact(int);

int main()

{

int num,fact_of_given_num;

printf(“Enter a number: \n “);

scanf(“%d”,&num);

fact_of_given_num = fact(num);

printf(“fact_of_given_num %d = %d \n”,num,fact_of_given_num);

return 0;

}

 

int fact(int n)

{

if(n==1)

return 1;

else

return(n*fact(n-1));

}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.