C++ Online Compiler
Example: C++ program to find the factorial of a number using for loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to find the factorial of a number using for loop #include <iostream> using namespace std; int main() { int x, i, f = 1; // x denotes input number // f denotes factorial value cout << "Enter an integer to find the fact::\n"; cin >> x; if (x > 0) { for (i = 1; i <= x; ++i) { f *= i; } cout << "Factorial of " << x << " = " << f << "\n"; } else { cout << "Sorry, input number should be positive number greater than 1!\n"; } return 0; }
5
Output
Clear
ADVERTISEMENTS