Calculate Factorial Using recursive function

-- Leave a Comment
Hello Here is a program for Reading a number from user and print the factorial of that number using recursive function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<conio.h>
int factf(int);
void main()
 {
    int a, fact;
      printf("enter a number to find its factorial:- ");
      scanf("%d",&a);
      fact=factf(a);
      printf("Factorial is %d",fact);
      getche();
   }
int factf(int x)
 {
    int y=1;
    if(x !=0)
       y=x*factf(x-1);
      return(y);
   }

Recursive function is that function that falls it self. We should set certain conditions if not the program will be of infinite loop.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment