Advertisement
CzarnyBarszcz

DEC TO HEX

Nov 20th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int dec,hex[20],n=0;
  9. cin>> dec;
  10. for(int i=0;i<200;i++)
  11. {
  12. hex[i]=dec%16;
  13. dec=dec/16;
  14. n=i;
  15. if(dec==0)
  16. {
  17. break;
  18. }
  19. }
  20. for(int j=n;j>=0;j--)
  21. {
  22. if(hex[j]==10)
  23. {
  24. cout<<"A";
  25. }
  26. if(hex[j]==11)
  27. {
  28. cout<<"B";
  29. }
  30. if(hex[j]==12)
  31. {
  32. cout<<"C";
  33. }
  34. if(hex[j]==13)
  35. {
  36. cout<<"D";
  37. }
  38. if(hex[j]==14)
  39. {
  40. cout<<"E";
  41. }
  42. if(hex[j]==15)
  43. {
  44. cout<<"F";
  45. }
  46. if(hex[j]<10)
  47. {
  48. cout<<hex[j];
  49. }
  50. }
  51. getch();
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement