Advertisement
wrahq

[ćw 1 / PD-2] Silnia (rekurencyjnie)

May 12th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. /*
  2.  
  3. Napisz program wyznaczajacy silnie podanej przez uzytkownika liczby.
  4.  
  5. */
  6.  
  7.  
  8. #include<iostream>
  9. using namespace std;
  10.  
  11.  
  12. int silnia(int n){
  13. if(n<2) return n;
  14. return n*silnia(n-1);
  15. }
  16.  
  17.  
  18. int main(){
  19.  
  20. cout << "Silnia wzorem rekurencyjnym." << endl << endl;
  21.  
  22. int liczba;
  23. cout << "Podaj liczbe, ktorej silnie chcesz obliczyc: ";
  24. cin >> liczba;
  25.  
  26. cout << "n! = " << silnia(liczba) << endl;
  27.  
  28. cin.ignore();
  29. cin.get();
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement