C++ Program to Find Factorial of a Number Using Iteration Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Factorial of a number n is the product of all integers from 1 to n. In this article, we will learn how to find the factorial of a number using iteration in C++. Example Input: 5Output: Factorial of 5 is 120Factorial of Number Using Iteration in C++To find the factorial of a given number we can use loops. First, initialize the factorial variable to 1, and then iterate using a loop from 1 to n, and in each iteration, multiply the iteration number with factorial and update the factorial with the new value. C++ Program to Find Factorial Using IterationThe below program shows how we can find the factorial of a given number using the iteration method. C++ // C++ program to find factorial of a number using iteration #include <iostream> using namespace std; int main() { // number n whose factorial needs to be find int n = 5; // initialize fact variable with 1 int fact = 1; // loop calculating factorial for (int i = 1; i <= n; i++) { fact = fact * i; } // print the factorial of n cout << "Factorial of " << n << " is " << fact << endl; return 0; } OutputFactorial of 5 is 120 Time Complexity: O(N), where N is the given numberAuxiliary Space: O(1) Comment More info T the_star_emperor Follow Improve Article Tags : C++ Programs C++ Basic Coding Problems factorial CPP Examples +1 More Explore C++ BasicsIntroduction to C++ Programming Language3 min readData Types in C++7 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++10 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library2 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples7 min read Like