pTutorial

New way to learn C programming

C Factorial program

In this section, you can learn, how to find factorial of any given number by user using for loop.

Example

Factorial of 5
=5*4*3*2*1
=120

C factorial program


//factorial
#include <stdio.h>
#include <conio.h>
void main()
{
  int c, n, fact = 1;
 
  printf("Enter a number to calculate it's factorial\n");
  scanf("%d", &n);
 
  for (c = 1; c <= n; c++)
  fact = fact * c;
 
  printf("Factorial of %d = %d\n", n, fact);
 
  getch();


Download C Factorial Program

Output of program

c program factorial

In this example, execute a for loop until the value of c is not equal to the entered number (n) and last print the fact variable.

See Also

How to write first program in node.js   |   Php5 method overloading   |   Php counter

QUOTES OF THE DAY

The heart of melody can never be put down.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER