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 create war file in eclipse   |   Php include function   |   Php sorting of array1

QUOTES OF THE DAY

Goal is tired by fire, brave men by adversity.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER