Q. Write a program to calculate factorial of given number using recursion
#BIT-C Programming-2019-GroupB-7No-6 Marks-Solution
==> Code goes like this:
#include<stdio.h>
int factorial(int); //funciton declaration||prototyping
int main()
{
int num,x;
printf("\n Enter any number: ");
scanf("%d",&num);
x=factorial(num);
printf("\n Factorial of %d is %d",num,x);
return 0;
}
int factorial(int n) //function definition
{
int fact=1;
if(n==1)
return fact;
else
fact=n*factorial(n-1); //recursive function
return fact;
}
Output
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Calculate factorial of given number using recursion - C
10:07 PM
C Programs
,
Calculate factorial of given number
,
OldQuestionSoluton2019C
,
Recursive function in C
Edit
0 comments:
Post a Comment