Skip to content

Instantly share code, notes, and snippets.

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 kolodziej/0736e324bf1ca0a3c81f to your computer and use it in GitHub Desktop.
Save kolodziej/0736e324bf1ca0a3c81f to your computer and use it in GitHub Desktop.
Obliczanie silni z obsługą parametrów linii poleceń
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char ** argv)
{
int n = 0;
int silnia = 1;
cout << "\tObliczanie silni" << endl;
if (argc >= 2)
{
n = atoi(argv[1]);
} else {
cout << "Podaj liczbe z jakiej mam policzyc silnie: ";
cin >> n;
}
for (int i = 1; i <= n; silnia *= i++);
cout << "n! = " << n << "! = " << silnia << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment