Skip to content
DATA STRUCTURE
DATA STRUCTURE

Learn everything about Data structure

  • Algorithms
  • DSA
  • Array
  • Stack
  • Queue
  • Matrix
  • Programs
DATA STRUCTURE

Learn everything about Data structure

Algorithm to Calculate factorial using function

YASH PAL, September 27, 2022March 6, 2023

In this tutorial, we will write an algorithm to calculate factorials using the function. using this algorithm we can make a program to calculate factorial using functions in most programming languages like java python c++ and c programming.

[br]

Algorithm to Calculate factorial using function.

1. Read N.
2. ANS=FACT(N).
3. Write ANS.
4. Exit
[br]
[This procedure is used to calculate the factorial of N]
1. Set ANS:=1
2. Repeat step 3 for I:=N to 1
3. Set ANS:=ANS*I
4. [End of Step 3 loop]
5. Return ANS.
6. Exit.
[br]
In the above algorithm first, we write the main program algorithm and then we write the algorithm for the function then we call that function in our main program. in the above function first, we read an integer N variable and then we call the function using that variable as input and assign its output to the ANS variable and then write it to the output screen and exit from the program.
[br]
In the function that calculates the factorial, we first set the value of the ANS variable to 1 and then repeat step 3 till the value of I become 1. in the loop we set the value of ANS to ANS*I and then return that ANS and exit from the function.
[br]
Remember that when we exit from the function the cursor returns to the program where it will be called.
[br]
Also, Read
  1. Algorithm to Find Maximum of Two Numbers
  2. Algorithm to Find Maximum of Three Numbers
  3. Algorithm to Input percentage From user and Print grade
  4. Algorithm to Print the Series 1 to N using for loop
  5. Algorithm to Print the Series 1 to N using while loop
  6. Algorithm to Print the Series 1 to N using Do While loop
  7. Algorithm to Reverse a given Number
  8. Algorithm to Find Whether a Number is Prime or Not
  9. Algorithm for Linear Search in Array
algorithms algorithm

Post navigation

Previous post
Next post

Leave a Reply

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

  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • About US
  • Contact US
  • Data Structures and algorithms tutorials
  • Digital Communication Tutorials
  • DMCA
  • HackerRank All Algorithms problems solutions
  • HackerRank C problems solutions
  • HackerRank C++ problems solutions
  • HackerRank Java solutions
  • HackerRank Python solutions
  • Human Values Tutorials
  • Internet of Things Tutorials
  • Privacy Policy
©2025 DATA STRUCTURE | WordPress Theme by SuperbThemes