Factorial of a number


Write a C Program to find factorial of a given number (using for loop).

						
 #include  <stdio.h>

void main()
{
  int  i , n ;
  long  f=1 ;  /* Factorials are long numbers */

  printf("Enter an integer greater than or equal to zero: ") ;
  scanf("%d" , &n) ;

  for(i=1 ; i<=n ; i++)
    f=f*i ;

  printf("Factorial of %d is %ld" , n , f) ;
}

Write a C Program to find factorial of a given number (using while loop).

						
 #include  <stdio.h>

void main()
{
  int  i , n ;
  long fact=1;
 printf("Enter an integer greater than or equal to zero:\n");
 scanf("%d",&n);
 while(i<=n){
    fact=fact*i;
    i++;
 }
 printf("Factorial of %d is %ld",n,fact);
}            

								

Output :

Output