rmoronsv

Untitled

Dec 30th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. void recursive_itoa(int n, char s[])
  2. {
  3. long long int pn = 0;
  4. int sign = 1;
  5. char digit;
  6. static int i = 0;
  7.  
  8. if (n < 0)
  9. {
  10. pn = -n;
  11. sign = -1;
  12. s[i++] = '-';
  13. }
  14. else
  15. pn = n;
  16.  
  17. if (pn / 10 > 0)
  18. {
  19. digit = (pn % 10) - '0'; //digit 3 2
  20. pn /= 10; //123 12
  21. recursive_itoa(pn, s);
  22. }
  23. else
  24. digit = (pn % 10) - '0'; // 1 1
  25.  
  26. s[i++] = digit;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment