fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <sstream>
  6. #include <queue>
  7. #include <deque>
  8. #include <bitset>
  9. #include <iterator>
  10. #include <list>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <functional>
  15. #include <numeric>
  16. #include <utility>
  17. #include <limits>
  18. #include <time.h>
  19. #include <math.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <assert.h>
  24. using namespace std;
  25.  
  26. // void fun()
  27. // {
  28. // // function calling itself is recursion
  29. // fun();
  30. // }
  31.  
  32. void printNto1(int n){
  33. // Base Case: Where the execution terminates [Mandatory]
  34. if (n == 0)
  35. return;
  36.  
  37. // What you do in each function call
  38. cout << n << " ";
  39. printNto1(n-1);
  40. }
  41. // Time Complexity: O(N)
  42. // Space Complexity: O(N)
  43. // Function call stack also takes some space
  44.  
  45. // input : 5
  46. // output: 5 4 3 2 1
  47.  
  48. // input : 3
  49. // output: 3 2 1
  50.  
  51. // Q2
  52. // input : 5
  53. // output: 1 2 3 4 5
  54.  
  55. // input : 3
  56. // output: 1 2 3
  57.  
  58. int main()
  59. {
  60. int n = 4;
  61. printNto1(4);
  62.  
  63. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
4 3 2 1