Advertisement
alisadafi

change-base

Dec 23rd, 2022 (edited)
40
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | Help | 0 0
  1. # include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.   int num, base;
  7.   cin >> num;
  8.   cin >> base;
  9.   int top = 0;
  10.  
  11.   int arr[1000];
  12.   while (num != 0) {
  13.     arr[top] = num % base;
  14.     num /= base;
  15.     top ++;
  16.   }
  17.   for(int i = 1; i <= top; i ++){
  18.     cout << arr[top - i];
  19.   }
  20.   return 0;
  21. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement