Friday 11 December 2015

C++ Program to find factorial of a number (Note: Factorial of positive integer n = 1*2*3*...*n)

#include <iostream>
using namespace std;

int main() {
    int i, n, factorial = 1;

    cout<<"Enter a positive integer: ";
    cin>>n;

    for (i = 1; i <= n; ++i) {
        factorial *= i;   // factorial = factorial * i;
    }

    cout<< "Factorial of "<<n<<" = "<<factorial;
    return 0;
}

No comments:

Post a Comment