Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include<math.h>
  3. using namespace std;
  4. int main()
  5. {
  6. cout << "1 pt din baza 10 in orice baza" << endl << "2 pt baza 2 in baza 10" << endl;
  7. int var,d, e = 1000, f, g = 0, k = 0;
  8. cin >> var;
  9. if (var == 1)
  10. {
  11. int a, c, i, b, v[100];
  12. cin >> a;
  13. cin >> b;
  14. c = a;
  15. i = 0;
  16. while (c)
  17. {
  18. v[i] = c % b;
  19. c = c / b;
  20. i++;
  21. }
  22. int p = i;
  23. for (i = p - 1; i >= 0; i--)
  24. if (v[i] <= 9)
  25. cout << v[i];
  26. else
  27. {
  28. if (v[i] == 10)
  29. cout << "A";
  30. if (v[i] == 11)
  31. cout << "B";
  32. if (v[i] == 12)
  33. cout << "C";
  34. if (v[i] == 13)
  35. cout << "D";
  36. if (v[i] == 14)
  37. cout << "E";
  38. if (v[i] == 15)
  39. cout << "F";
  40. }
  41.  
  42.  
  43. }
  44. else
  45. if (var == 2)
  46. {
  47. cout << "nr=";
  48. cin >> d;
  49. while (d)
  50. {
  51. f = d % e;
  52.  
  53. while (f)
  54. {
  55. if (f % 10 <= 9)
  56. k = k + (f % 10)*pow(2, g);
  57.  
  58. g++;
  59. f = f / 10;
  60.  
  61. }
  62. d = d / e;
  63. }cout << k;
  64.  
  65.  
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement