C Program for Factorial of a Number

C Program for Factorial

How Factorial is Calculated?

Factorial is simply defined as “the product of an integer (n) and all the integers below it. For Example- Factorial three ( 3! ) is equal to 6

Factorial of a number ‘N’ is represented as N!

N! is calculated as N*(N-1)*(N-2)*(N-3)……*1

Let the Value of N is 5 then Factorial of N is 5*4*3*2*1=120

 

C Program for Factorial

 

C Program for Factorial of a Number:

#include <stdio.h>
#include <conio.h>
int main()
{
  int n, i;
  unsigned long long fact = 1;
  clrscr();

  printf(“Enter a number to Find its Factorial: “);
  scanf(“%d”,&n);

  if (n < 0)
    printf(“Error! Factorial of a negative number doesn’t exist”);

  else
  {
    for(i=1; i<=n; i++)
    {
        fact = fact * i;
    }
  printf(“Factorial of %d = %llu”, n, fact);
  }

  getch();
  return 0;
}

 

Output:

Enter a number to Find its Factorial: 6

Factorial of 6 = 720


 

Technym is a Tech Blog for all those who want to get in depth of the Technology. We Provide Various Online Money Making Guides, tech tutorials, tips and tricks and Tech Updates. Our Main motive is just to spread informative Content and works under the philosophy of Keeping the Readers Informed.

Also Find C Program for factorial in other Programming languages as well

Please Bookmark this Page if you like to find more such Programming Codes in various Languages.

One Comment on “C Program for Factorial of a Number”

Leave a Reply

Your email address will not be published. Required fields are marked *