#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;
}
Code Example |
---|
Cpp :: c++ uint8_t header |
Cpp :: c++ loop trhought object |
Cpp :: c++ std string to float |
Cpp :: fill vector with zeros c++ |
Cpp :: how to make a vector in c++ |
Cpp :: text color c++ |
Cpp :: QVariant to int |
Cpp :: constrain function in arduino |
Cpp :: print fps sfml |
Cpp :: c++ if statement |
Cpp :: c++ thread wait fro 1 sec |
Cpp :: rethrow exception c++ |
Cpp :: c++ formatting |
Cpp :: c++ add input in |
Cpp :: c++ compare type |
Cpp :: Shuffle String leetcode solution in c++ |
Cpp :: maximum subarray leetcode c++ |
Cpp :: how can I delete a substring from a string in c++? |
Cpp :: web dev c++ |
Cpp :: concatenate string in cpp |
Cpp :: c++ pass function as argument |
Cpp :: javascript if else exercises |
Cpp :: malloc 2d array cpp |
Cpp :: queue cpp |
Cpp :: check if cin got the wrong type |
Cpp :: progress indicator raytracer |
Cpp :: unambiguous |
Cpp :: c++ exeption handling |
Cpp :: reverse the number codechef solution in c++ |
Cpp :: mpi wait |