- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Factorial of a non-negative integer n is the product of all the positive integers that are less than or equal to n.

For example: The factorial of 6 is 720.

6! = 6 * 5 * 4 * 3 * 2 *1 6! = 720

The factorial of an integer can be found using a recursive program or an iterative program.

A for loop can be used to find the factorial of a number using an iterative program. This is demonstrated as follows.

#include <iostream> using namespace std; int main() { int n = 6, fact = 1, i; for(i=1; i<=n; i++) fact = fact * i; cout<<"Factorial of "<< n <<" is "<<fact; return 0; }

Factorial of 6 is 720

In the above program, the for loop runs from 1 to n. For each iteration of the loop, fact is multiplied with i. The final value of fact is the product of all numbers from 1 to n. This is demonstrated using the following code snippet.

for(i=1; i<=n; i++) fact = fact * i;

- Related Questions & Answers
- C++ Program to Find Factorial of a Number using Recursion
- C++ Program to Find Factorial of a Number using Dynamic Programming
- C++ program to Calculate Factorial of a Number Using Recursion
- C++ Program to Find Fibonacci Numbers using Iteration
- C++ program to find first digit in factorial of a number
- 8085 program to find the factorial of a number
- 8086 program to find the factorial of a number
- Python program to find factorial of a large number
- Java program to find the factorial of a given number using recursion
- Find the factorial of a number in pl/sql using C++.
- How to Find the Factorial of a Number using Python?
- C++ Program to Find Factorial
- Program for factorial of a number in C program
- Write a Golang program to find the factorial of a given number (Using Recursion)
- Python Program to find the factorial of a number without recursion

Advertisements