Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. //
  2. // Fakultät.cpp
  3. // Created by Florian Gudat on 26.10.16.
  4. //
  5.  
  6. #include <iostream>
  7.  
  8. int main() {
  9.  
  10. int n;
  11. std::cout << "Bitte geben Sie einen gültigen Wert für n! ein.\n";
  12. std::cout << "n = ";
  13. std::cin >> n;
  14.  
  15. int m = n;
  16. int r = 1;
  17.  
  18. if (n > 0) {
  19.  
  20. while (n > 0) {
  21. r = r * n;
  22. n = n - 1;
  23. }
  24. std::cout << "Ergebnis:\n";
  25. std::cout << m << "! = " << r;
  26.  
  27. } else if (n == 0) {
  28.  
  29. r = 0;
  30. std::cout << "Ergebnis:\n";
  31. std::cout << m << "! = " << r;
  32.  
  33. } else {
  34.  
  35. std::cout << "Ungültige Eingabe";
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement