Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<math.h>
- using namespace std;
- int main()
- {
- cout << "1 pt din baza 10 in orice baza" << endl << "2 pt baza 2 in baza 10" << endl;
- int var,d, e = 1000, f, g = 0, k = 0;
- cin >> var;
- if (var == 1)
- {
- int a, c, i, b, v[100];
- cin >> a;
- cin >> b;
- c = a;
- i = 0;
- while (c)
- {
- v[i] = c % b;
- c = c / b;
- i++;
- }
- int p = i;
- for (i = p - 1; i >= 0; i--)
- if (v[i] <= 9)
- cout << v[i];
- else
- {
- if (v[i] == 10)
- cout << "A";
- if (v[i] == 11)
- cout << "B";
- if (v[i] == 12)
- cout << "C";
- if (v[i] == 13)
- cout << "D";
- if (v[i] == 14)
- cout << "E";
- if (v[i] == 15)
- cout << "F";
- }
- }
- else
- if (var == 2)
- {
- cout << "nr=";
- cin >> d;
- while (d)
- {
- f = d % e;
- while (f)
- {
- if (f % 10 <= 9)
- k = k + (f % 10)*pow(2, g);
- g++;
- f = f / 10;
- }
- d = d / e;
- }cout << k;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement