Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int binary_n = 0, k = 1;
- //перевод в двоичную
- while (n) {
- binary_n += (n % 2) * k;
- k *= 10;
- n /= 2;
- }
- //разворот числа
- int mod_n, reversed_n = 0;
- while (binary_n != 0) {
- mod_n = binary_n % 10;
- reversed_n = (reversed_n * 10) + mod_n;
- binary_n /= 10;
- }
- //число из двоичной в 10-ю
- int answer_n = 0, prom = 1;
- while (reversed_n) {
- int mod_10 = reversed_n % 10;
- reversed_n /= 10;
- answer_n += mod_10 * prom;
- prom *= 2;
- }
- cout << answer_n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement