Factorial of a number using recursion in C Language
Write a Factorial of a number in C program to compute the factorial of the given positive integer using recursive function.
User needs to enter the positive Integer whose factorial needs to be found and after the program will print the factorial of integer. Function rec (int num) is function which will be called recursively to find the Factorial of a number.
Factorial of a number using recursion in C
#include <stdio.h> #include<conio.h> int rec(int num); void main() { int num, fact; printf(“\nEnter any number: “); scanf (“%d”, &num); fact=rec (num); printf(“\nFactorial Value = %d”, fact); getch(); } int rec (int num) { int f; if (num==1) return (1); else f=num*rec(num-1); return (f); }
Leave a Reply