Facebook
From Cute Crocodile, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 129
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int silnia(int x){
  8.  
  9.     if (x==0){
  10.         return 1;
  11. }
  12.     else {
  13.         return x*silnia(x-1);
  14. }
  15. }
  16.  
  17. int main(){
  18.  
  19.  
  20. int x;
  21.  
  22. cout <<"Podaj liczbe dla której program obliczy silnie:\n";
  23. cin >> x;
  24.  
  25. if ( x>12 ){
  26.  
  27.     cout << "Maksymalna wartość argumentu x wynosi liczba 12.\n Nie możesz podać wartości większej niż ta.\n";
  28.  
  29. }
  30. else {
  31.  
  32.     cout << "Silnia jest równa: " << silnia(x) << ".\n";
  33.  
  34. }
  35. return 0;
  36. }