Answers for "making factorial in c programming"

C
3

factorial of a given number in c

//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;
}
Posted by: Guest on June-15-2020
0

making factorial in c programming

#include <stdio.h>
 
int main()
{
  int i, num, fact = 1;
 
  printf("Enter Number to Calculate Factorial: \n");
  scanf("%d", &num);
  
  for (i = 1; i <= num; i++){
      fact = fact * i;
  }
    
  printf("Factorial of %d = %d\n", num, fact);
 
  return 0;
}
Posted by: Guest on June-28-2021

Code answers related to "C"

Browse Popular Code Answers by Language