A Program to Find Factorial of a Number
In this example, we are giving a program to find the factorial of a number.
Program to find factorial:
#include <iostream>using namespace std;int main() {int n, i;unsigned long long fact = 1;cout << "Enter an integer: ";cin >> n;// shows error if the user enters a negative integerif (n < 0)cout << "Factorial of a negative number doesn't exist.";else {for (i = 1; i <= n; ++i) {fact *= i;}cout << "Factorial = " << fact;}return 0;}
Output:
Enter an integer: 7 Factorial = 5040