Sachees

najprostsza silnia jaka moze byc

Aug 27th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. long long factorial(int);
  4. int main()
  5. {
  6. int number;
  7. std::cout << "W tym programie wyliczymy silnie. Podaj liczbe(ostrzezenie: silnia bedzie duza, wiec zaleca sie nie uzywanie zbyt duzych liczb): \n";
  8. for(;;)
  9. {
  10. std::cin >> number;
  11. if(!std::cin)
  12. break;
  13. std::cout << "Silnia z liczby " << number << " wynosi " << factorial(number) << ". \n";
  14. std::cout << "Podaj kolejna liczbe lub podaj litere aby zakonczyc.\n";
  15. std::cin.clear();
  16. }
  17. return 0;
  18. }
  19.  
  20. long long factorial(int number)
  21. {
  22. if(number == 1)
  23. return 1;
  24. else
  25. return number * factorial(number - 1);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment