factorial c program using for loop
snippet in c

factorial of a given number in c

user4098

//Factorial of a given number
#include <stdio.h>

//This function returns factorial of the number passed to it 
long int factorialOf(int number){
    long int factorial = 1;
    while(number){
        factorial*=number;
        number-=1;
    }
    return factorial;
}

int main(void) {
	int n;
	printf("Find factorial of \n");
	scanf("%d",&n);
	printf("\nThe factorial of %d is %ld",n,factorialOf(n));
	return 0;
}

factorial c program using for loop

user5139

#include<stdio.h>
int main(){
  int i,f=1,num;
 
  printf("Enter a number: ");
  scanf("%d",&num);
 
  for(i=1;i<=num;i++)
      f=f*i;
 
  printf("Factorial of %d is: %d",num,f);
  return 0;
}

factorial code

user3543

#include <stdio.h> 
  
// function to find factorial of given number 
int factorial( int n) 
{ 
    int res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
} 
  
int main() 
{ 
    int num = 5; 
    printf( 
        "Factorial of %d is %d", num, factorial(num)); 
    return 0; 
}