Factorial of a Number in C++

 This program calculates the factorial of a given positive integer.

#include <iostream>

int main() {

    int n;

    std::cout << "Enter a positive integer: ";

    std::cin >> n;

    unsigned long long factorial = 1;

    for(int i = 1; i <= n; ++i) {

        factorial *= i;

    }

    std::cout << "Factorial of " << n << " = " << factorial << std::endl;

    return 0;

}

No comments:

Post a Comment

MS Excel Logical Functions

Logical functions in Excel are powerful tools that help you make decisions based on conditions. Whether you're comparing values or testi...

Post Count

Loading...