Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- void perevod_1 (int n, int osn_2)
- {
- int m = osn_2;
- int c = 1;
- int znach = n;
- int result = 0;
- while (znach/m != 0)
- {
- m *= osn_2;
- c++;
- }
- int *arr = new int[c];
- for (int i=0; i<c; i++)
- {
- arr[i] = n % osn_2;
- n /= osn_2;
- }
- for (int i=c-1; i>=0; i--)
- result += arr[i]*pow(10, i);
- cout << result << " ";
- }
- void perevod_2 (int n, int osn_1, int osn_2)
- {
- int c = 1;
- int m = 10;
- int znach = n;
- int result;
- while (znach/m != 0)
- {
- m *= 10;
- c++;
- }
- int *arr = new int[c];
- for (int i=0; i<c; i++)
- {
- arr[i] = n % 10;
- n /= osn_2;
- }
- for (int i = c-1; i >= 0; i--)
- result += arr[i]*pow(osn_1, i);
- cout << result << " ";
- }
- int main()
- {
- int n, osn_1, osn_2;
- cin >> n >> osn_1 >> osn_2;
- if (osn_2 < osn_1)
- perevod_1(n, osn_2);
- else perevod_2 (n, osn_1, osn_2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement