Advertisement
Tobiahao

REKURENCJA_02

Mar 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. /*
  2. Napisz program, w którym zdefiniujesz funkcję rekurencyjną konwertującą zapis dziesiętny liczby naturalnej większej od zera na zapis szesnastkowy.
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. void convert_to_hexadecimal(unsigned long int number)
  8. {
  9.  
  10.     if(number == 0) return;
  11.    
  12.     convert_to_hexadecimal(number/16);
  13.     number %= 16;
  14.  
  15.     switch (number) {
  16.         case 10: printf("A"); break;
  17.         case 11: printf("B"); break;
  18.         case 12: printf("C"); break;
  19.         case 13: printf("D"); break;
  20.         case 14: printf("E"); break;
  21.         case 15: printf("F"); break;
  22.         default: printf("%lu", number);
  23.     }
  24. }
  25.  
  26. int main(void)
  27. {
  28.     convert_to_hexadecimal(999);
  29.     printf("\n");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement