C Program to find the factorial of any number.
#include<stdio.h>
int factorial(int number)
{
if (number==1 || number==0)
{
return 1;
}
else{
return (number * factorial(number-1));
}
}
int main()
{
int num;
printf("Enter the number you want the factorial of\n");
scanf("%d", &num);
printf("The factorial of %d is %d\n", num, factorial(num));
return 0;
}
OUTPUT:
Enter the number you want the factorial of
3
The factorial of 3 is 6
Enter the number you want the factorial of
4
Enter the number you want the factorial of
0
The factorial of 0 is 1
Tysm
ReplyDelete