Advertisement
Guest User

factorial

a guest
Apr 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. //Sebastian Moore
  2. //CS 52 Spring 2019
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. int
  10. main ()
  11. {
  12.  
  13. int num1;
  14.  
  15. unsigned int x;
  16.  
  17. unsigned long long factorial = 1;
  18.  
  19. bool positive = true;
  20.  
  21. while (positive == true)
  22.  
  23. {
  24.  
  25. cout << "Enter an integer: ";
  26.  
  27. cin >> num1;
  28.  
  29. for(int x = 1; x <= num1; ++x)
  30. {
  31. factorial *= x;
  32. }
  33.  
  34. cout << num1 << "! = " << factorial;
  35. }
  36.  
  37. if (num1 > 0)
  38.  
  39. {
  40.  
  41. positive = false;
  42.  
  43. }
  44.  
  45. else
  46.  
  47. {
  48.  
  49. cout << "Error: number must be positive." << endl;
  50.  
  51. }
  52.  
  53.  
  54.  
  55. return 0;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement