Skip to main content

Posts

Showing posts from September, 2017

Factorial Program in C using Recursion

#include<stdio.h> #include<conio.h> void main() {    int n, fact;    clrscr();    printf("\nEnter a Number: ");    scanf("%d",&n);    fact = factorial(n);    printf("\nThe Factorial value is: ");    printf("%d",fact);    getch(); } factorial(int n) {     int fact;     if(n==1)     {        return(1);     }     else     { fact = n * factorial(n-1); return fact;     } } Output: Enter the value: 5 The Factorial value is: 120