//Written by MA Saleh
#include<stdio.h>
//This is a function for Factorial Number
long long find_factorial(int n)
{
if (n == 0)
{
return 1;
}
else
{
return (n * find_factorial (n - 1)); //using recursion
}
}
int main()
{
int num;
long long int factorial;
printf("Enter a number for find factorial: ");
while(scanf("%d", &num) == 1) //Take a number as input from user
{
if(num < 0)
{
printf("Negative is not allowed\n");
}
else
{
factorial = find_factorial(num); //call the function
printf("%d! = %lld\n", num, factorial); //print the result
}
}
return 0;
//Copyright@MAS
}
0 comments:
Post a Comment