-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbases.cpp
More file actions
32 lines (27 loc) · 854 Bytes
/
Copy pathbases.cpp
File metadata and controls
32 lines (27 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* TODO: write a program that reads an integer b (say b < 10), and
* another integer n, and then prints a string that represents the
* integer n in base b. E.g., if b=7 and n=94, your program would
* output digits "163", as 94 = 1*49 + 6*7 + 3. ("361" is also ok if
* you print the least significant digit first). Or if b=2 and n=7,
* then you would print "111" since 7 = 1*4 + 1*2 + 1. */
#include <iostream>
using std::cin;
using std::cout;
using std::string;
int main()
{
int b, n;
std::cin >> b >> n;
if (n == 0) {
std::cout << "0";
return 0;
}
while (n > 0) {
int rem = n % b; // Find the remainder (this gives us the current digit)
std::cout << rem; // print digit
n /= b; // redu7ce n by dividing by b, n/=b updates value of n to quotient
}
/* your answer goes here... */
return 0;
}
// vim:foldlevel=2