fork download
  1. #include <stdio.h>
  2.  
  3. void print_hex(int n){
  4. if(n <= 9){
  5. printf("%d",n);
  6. }else{
  7. switch(n){
  8. case(10):
  9. printf("A");
  10. break;
  11. case(11):
  12. printf("B");
  13. break;
  14. case(12):
  15. printf("C");
  16. break;
  17. case(13):
  18. printf("D");
  19. break;
  20. case(14):
  21. printf("E");
  22. break;
  23. case(15):
  24. printf("F");
  25. break;
  26. }
  27. }
  28. }
  29.  
  30. void tohex(int n){
  31.  
  32. if(n == 0){
  33. printf("0");
  34. }
  35. if(n >= 16){
  36. tohex(n / 16);
  37. }
  38.  
  39. print_hex(n % 16);
  40.  
  41. }
  42.  
  43. int main(void) {
  44. int n;
  45. scanf("%d",&n);
  46.  
  47. tohex(n);
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5284KB
stdin
15
stdout
F