Home About Contact Privacy Terms Disclaimer
TECHAntena
Last Updated On: September 16, 2016
Editor: Adeeb C

C Program & Algorithm to find the factorial of a given number

Category: C,Programing
Tags

This is the C program code and algorithm for finding the factorial of a given number.

Aim:

Write a C program to find the factorial of a given number.

Algorithm:

Step 1: Start
Step 2: Read number n
Step 3: Set f=1
Step 4: Repeat step 5 and step6 while n>0
Step 5: Set f=f*n
Step 6: Set n=n-1
Step 7: Print factorial f
Step 8: Stop

Program code

#include<stdio.h>
#include<conio.h>

void main( )
{
clrscr( )
 int num,f=1;
 printf("Enter the number: ");
 scanf("%d",&num);

while(n>0)
{
  f=f*n;
  n--;
}
printf("The factorial is %d",f);
getch( );
}

Output

Enter the number : 5

The factorial is 120