June 9, 2023
program to use find out the factorial of a number in C language
#include <stdio.h>
long int factorial(int n);
int main()
{
int num;
printf("Enter a number : ");
scanf("%d",&num);
if(num<0)
printf("No factorial of negative number\n");
else
printf("Factorial of %d is %ld\n",num,factorial(num));
return 0;
}
long int factorial(int n)
{
int i;
long int fact=1;
if(n==0){
return 1;
}
for(i=n; i>1; i--){
fact*=i;
}
return fact;
}
output
Enter a number : 8
Factorial of 8 is 40320
by : Ajaj Khan
Quick Summary:
program to use find out the factorial of a number in C language copy #include <stdio.h> long int factorial(int n); int main() { int num; printf(“Enter a number : “); scanf(“%d”,&num); if(num1; i–){ fact*=i; } return fact; } output Enter a number : 8 Factorial of 8 is 40320