fork download
  1. #include <stdio.h>
  2.  
  3. void tohex(int n) {
  4. if(n==0){
  5. return;
  6. }
  7. tohex(n/16);
  8. int digit=n%16;
  9. if(digit<10){
  10. printf("%d",digit);
  11. }else{
  12. printf("%c",'A'+(digit-10));
  13. }
  14. }
  15.  
  16. int main(void) {
  17. int a;
  18. printf("正の整数を入力してください: ");
  19. scanf("%d", &a);
  20.  
  21. if (a == 0) {
  22. printf("0\n");
  23. } else if (a > 0) {
  24. tohex(a);
  25. printf("\n");
  26. } else {
  27. printf("正の整数を入力してください。\n");
  28. }
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5320KB
stdin
254
stdout
正の整数を入力してください: FE