Thursday, December 22, 2011

C Program for Factorial useing Recursion....

#include<stdio.h>
#include<conio.h>
long int fact(long int);
 void main()
 { 
   long int  num,f;
   clrscr();
   printf("Input a number: ");
   scanf("%ld",&num);
   f=fact(num);
   printf("\nFactorial is %ld",f);
   getch();
 }
 long int fact(long int n)
 {
    if(n==0)
         return 1;
    else 
             return(n*fact(n-1)); 
 }

No comments:

Post a Comment