Skip to content

Instantly share code, notes, and snippets.

@juanfal
Last active October 11, 2023 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanfal/aa19aa5fd6093f1905fd to your computer and use it in GitHub Desktop.
Save juanfal/aa19aa5fd6093f1905fd to your computer and use it in GitHub Desktop.
Factorial using for loop
// factorial.for.cpp
// juanfc 2023-10-11
// plain for loop to compute a factorial
// https://gist.github.com/aa19aa5fd6093f1905fd
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "n?: ";
// cin >> n;
n = 16;
long long unsigned f = 1;
for (int i = 2; i <= n; ++i)
f *= i;
cout << n << "!: " << f << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment