factorial-calculator

Create a C++ program to calculate the factorial of a given positive integer. The user inputs the integer, and the program calculates and displays its factorial.

To calculate the factorial of a positive integer, you can use a simple loop to multiply the integer by all the positive integers less than itself. The factorial of 0 is defined to be 1. Here's a sample C++ program to calculate the factorial:

#include <iostream> using namespace std; int main() { int num; cout << "Enter a positive integer: "; cin >> num; int factorial = 1; for (int i = 1; i <= num; ++i) { factorial *= i; } cout << "The factorial of " << num << " is: " << factorial << endl; return 0; }

Rent this identity for $5/month