Answers for "find factorial of number c++"

C++
0

Write a C++ program to calculate factorial of a number.

#include <iostream>
using namespace std;

int main() {

    // #ifndef ONLINE_JUDGE // not part of code, used to beautify input output
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    int n, i, fact;
    cin >> n;
    fact = n;

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

    cout << fact;

    return 0;
}
Posted by: Guest on October-25-2021

Code answers related to "find factorial of number c++"

Browse Popular Code Answers by Language