jasonpogi1669

Recursive Void Function inside Main Function using C++

Aug 2nd, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     function<void(int)> Print = [&](int n) {
  9.       if (n == 1) {
  10.           cout << 1 << " ";
  11.       } else {
  12.           Print(n - 1);
  13.           cout << n << " ";
  14.       }
  15.     };
  16.     Print(n);
  17.     return 0;
  18. }
  19.  
Add Comment
Please, Sign In to add comment