Advertisement
VEGASo

Lab #2 Ex. 2

Oct 25th, 2022 (edited)
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. //////////////////////////////////////////// Lab 2 Ex. 2.cpp
  2. #include <iostream>
  3. #include "check.h"
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.     setlocale(LC_ALL, "Russian");
  12.     int a;
  13.  
  14.     a = getNumberForFactorial();
  15.  
  16.     cout << "Ответ: " << factorial(a) << endl;
  17.  
  18.     return 0;
  19. }
  20. ////////////////////////////////////////////
  21.  
  22.  
  23. //////////////////////////////////////////// check.cpp
  24. #include "check.h"
  25. #include <iostream>
  26.  
  27. using namespace std;
  28.  
  29. int getNumberForFactorial()
  30. {
  31.     int c;
  32.     cout << "Введите положительное значение до 12 включительно: ";
  33.     cin >> c;
  34.  
  35.     if ( (c < 1) || (c>12) )
  36.         return getNumberForFactorial();
  37.     else
  38.         return c;
  39. }
  40.  
  41. unsigned int factorial(unsigned int x)
  42. {
  43.     return x == 0 ? 1 : x * factorial(x - 1);
  44. }
  45. ////////////////////////////////////////////
  46.  
  47.  
  48.  
  49. ////////////////////////////////////////////check.h
  50. #ifndef SPHERE_H // или #programa once
  51. #define SPHERE_H
  52.  
  53.  
  54. int getNumberForFactorial();
  55. unsigned int factorial(unsigned int x);
  56.  
  57.  
  58. #endif
  59. ////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement