fork download
  1. #include <stdio.h>
  2.  
  3. int digit(int number, int n) {
  4. if (n <= 1) {
  5. return number % 10;
  6. }
  7. return digit(number / 10, n - 1);
  8. }
  9.  
  10. int main(void) {
  11. // your code goes here
  12. printf("%i\n", digit(12345, 1));
  13. printf("%i\n", digit(12345, 2));
  14. printf("%i\n", digit(12345, 3));
  15. printf("%i\n", digit(12345, 4));
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
5
4
3
2