Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. int digits(int n) {
  2.     int d = 1;
  3.     int temp = n;
  4.     while ((temp /= 10) != 0) {
  5.         d++;
  6.     }
  7.     return d;
  8. }
  9.  
  10. int digitByIndex(int n, int i)
  11. {
  12.     int d = digits(n) - 1;
  13.     int temp = n;
  14.     while (d != i)
  15.     {
  16.         temp /= 10;
  17.         d--;
  18.     }
  19.     return temp % 10;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement