fork download
  1. #include <stdio.h>
  2.  
  3. void tohex(int n) {
  4. if (n == 0) {
  5. return; }
  6. tohex(n / 16);
  7. int x=n%16;
  8. if (x<10) {
  9. printf("%d",x);
  10. }
  11. else if(x==11){
  12. printf("A");
  13. }
  14. else if(x==11){
  15. printf("B");
  16. }
  17. else if(x==12){
  18. printf("C");
  19. }
  20. else if(x==13){
  21. printf("D");
  22. }
  23. else if(x==14){
  24. printf("E");
  25. }
  26. else if(x==15){
  27. printf("F");
  28. }
  29. }
  30.  
  31. int main() {
  32. int n;
  33. scanf("%d", &n);
  34. if (n > 0) {
  35. printf("16進数表記は");
  36. tohex(n);
  37. }
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5320KB
stdin
255
stdout
16進数表記はFF