#include<stdio.h>
long factorial(int);
int main()
{
int num;
long f;
printf("Enter a number to find factorial\n");
scanf("%d", &num);
if (num < 0)
printf("Negative numbers are not allowed.\n");
else
{
f = factorial(num);
printf("%d! = %ld\n", num, f);
}
return 0;
}
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
Hay friends .. AREA OF LANGUAGE IS TOO WIDE BUT NOW APPROXIMATE THEORY AND "C PROGRAMING CODES" ARE AVAILABLE . GOPAL KRISHNA "CHAUHAN"
Thursday, 16 August 2012
C program : Factorial using recursion
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment