Advertisement
El_GEMMY

Print digits using recursion

Sep 15th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(v) v.begin(),v.end()
  4. #define rall(v) v.rbegin(),v.rend()
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define MOD 1000000007
  8. #define PI 3.14159265
  9. #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
  10. #define nl '\n'
  11. void Start_Crushing(){
  12.     ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  13. #ifndef ONLINE_JUDGE
  14.     freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  15.     freopen("error.txt", "w", stderr);
  16. #endif
  17. }
  18. void printing(int n){
  19.     if(n <= 0) return;
  20.  
  21.     printing(n / 10);
  22.     cout << n % 10 << ' ';
  23.  
  24. }
  25. void solve(){
  26.     int n; cin >> n;
  27.     if(n == 0){
  28.         cout << 0;
  29.         return;
  30.     }
  31.     printing(n);
  32. }
  33. int main(){
  34.     Start_Crushing();
  35.  
  36.     int t = 1;
  37.     /*is Single Test case?*/ cin >> t;
  38.     while (t--) {
  39.         solve();
  40.         cout << "\n";
  41.     }
  42.  
  43.     cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement