Factorial Program in C using 6 different ways

Factorial program in C

Here, you will know about factorial and get the example code to make factorial program in c using 6 different ways.

What is Factorial?

The product of all positive integers less than or equal to a specific number is a factorial. To find the Factorial of a number calculate the product of all the integers from 1 to that number or from number to 1(in reverse number order). 

For example:- 

Factorial of 6 is 1*2*3*4*5*6 = 720.

or

Factorial of 6 is 6*5*4*3*2*1 = 720.

What is the factorial of 100

Factorial of 100 will be :

= 100 * 99 * 98 * 97 * 96……………. * 3 * 2 * 1

=93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

or

= 9.332622e+157

 

Factorial Algorithm

Step 1: Initialize f =1

Step 2: Input the value of n( whose factorial is to be found).

Step 3: Initialize i =1,f=1.

Step 4: while i < =n, repeat step 5 and step 6

Step 5: The value of i should be multiplied by f and saved in f.

Step 6: Increment value of i with 1.

Step 7: Print the value of variable f as the factorial of given number.

Factorial Flowchart

factorial flowchart dfd

Now we knows the Logic, Algorithm, and Flowchart of Factorial. Let’s implements it with coding using six different methods.

 

  Factorial Program using 6 different ways

 

Factorial Program In C Using For Loop

Output

factorial program output1

Factorial Program In C Using While Loop

Output

factorial program output2

Factorial program in c using function

Output

Factorial program in c using function

Factorial Program in C Using Recursion 

Output

Factorial program in c using recursion

 

Factorial Program Using Ternary Operator

Output

factorial Program Using Ternary Operator

 

Factorial Program Using Pointers in C

Output

Factorial Program Using Pointers in C

 

Check out our other C programming Examples

Leave a Comment

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

Scroll to Top