Advertisement
STANAANDREY

lambda factorial

May 10th, 2021
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     auto fact = [&](auto self, int x)->int {
  6.         if (!x) {
  7.             return 1;
  8.         }
  9.         return x * self(self, x - 1);
  10.     };
  11.     cout << fact(fact, 7) << endl;//5040
  12.     return 0;
  13. }
  14.  
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement