Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find positive number factorial in C++

#include <iostream>
using namespace std;

int main() {
    int n;
    long double factorial = 1.0;

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

    if (n < 0)
        cout << "Error! Factorial of a negative number doesn't exist.";
    else {
        for(int i = 1; i <= n; ++i) {
            factorial *= i;
        }
        cout << "Factorial of " << n << " = " << factorial;    
    }

    return 0;
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #find #positive #number #factorial
ADD COMMENT
Topic
Name
8+6 =