#include <stdio.h>
long int factorial(int number) //function definition
{
if (number == 1 || number == 0) //base condition
{
return 1;
}
else
{
return (number * factorial(number - 1)); //function recalling
}
}
int main()
{
long int num;
printf("enter the number you want factorial of : \n");
scanf("%d", &num);
printf("the factorial of %ld is %ld", num, factorial(num)); //function call
return 0;
}
No comments:
Post a Comment