Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int dec, hex, resto, hf, rf;
- char A, B, C, D, E, F, r, h;
- int main()
- {
- printf("\nIntroduza um numero inteiro entre 0 e 255: ");
- scanf("%d", &dec);
- hex = dec / 16;
- resto = dec % 16;
- if( dec < 0 || dec > 255 )
- {
- printf("\n\t ERRO: Introduza um Numero entre 0 e 255 \n\n\n");
- return 0;
- }
- printf("\n\n Hex = ");
- if( hex <= 9 )
- {
- printf("%d", hex);
- }
- if( hex > 9 )
- {
- if( hex == 10 )
- h = 'A';
- if( hex == 11 )
- h = 'B';
- if( hex == 12 )
- h = 'C';
- if( hex == 13 )
- h = 'D';
- if( hex == 14 )
- h = 'E';
- if( hex == 15 )
- h = 'F';
- printf("%c", h);
- }
- if( resto <= 9 )
- {
- printf("%d", resto);
- }
- if( resto > 9 )
- {
- if( resto == 10 )
- r = 'A';
- if( resto == 11 )
- r = 'B';
- if( resto == 12 )
- r = 'C';
- if( resto == 13 )
- r = 'D';
- if( resto == 14 )
- r = 'E';
- if( resto == 15 )
- r = 'F';
- printf("%c", r);
- }
- printf("\n\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement