Advertisement
LEGEND2004

Functions

Feb 8th, 2024
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int N = 1e5 + 5;
  6. int a[N] , cnt[N];
  7.  
  8. // t <= 0 berk
  9. // 1 <= t <= 99 maye
  10. // t >= 100 qaz
  11.  
  12. string fi(int t){
  13.     if(t <= 0)
  14.         return "berk";
  15.     if(t <= 99)
  16.         return "maye";
  17.     return "qaz";
  18. }
  19. // n! = 1 * 2 * 3 * . . . (n - 1) * n = (n - 1)! * n
  20.  
  21. int f(int n){
  22.     if(n == 0)
  23.         return 1;
  24.     return n * f(n - 1);
  25. }
  26.  
  27.  
  28. int sum(int a , int b){
  29.     return a + b;
  30. }
  31.  
  32. /*
  33. recursive
  34. f(5) = 5 * f(4) = 5 * 24 = 120
  35. f(4) = 4 * f(3) = 4 * 6 = 24
  36. f(3) = 3 * f(2) = 3 * 2 = 6
  37. f(2) = 2 * f(1) = 2 * 1 = 2
  38. f(1) = 1 * f(0) = 1 * 1 = 1
  39. f(0) = 1
  40. */
  41.  
  42. bool parity(int n){
  43.     return n % 2 == 0;
  44. }
  45.  
  46. void solve(){
  47.     int n;
  48.     cin >> n;
  49.     if(n < 0)
  50.         return ;
  51.     cout << f(n) << '\n';
  52. }
  53.  
  54.  
  55. signed main()
  56. {
  57.     ios_base::sync_with_stdio(0);
  58.     cin.tie(0);
  59.  
  60.     int t;
  61.     cin >> t;
  62.     while(t--)
  63.         solve();
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement