Системы счисления | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Системы счисления

Как перевести число из 10 в -2 систему счисления и вывести его в формате 1 0 1 1 0 и с кол-во цифр https://code.sololearn.com/ct0AfC027fA1/?ref=app Формально, записью числа в (-2)-ичной системе счисления называется набор чисел a0, a1 ,..., an− 1 , каждое из которых равно 0 или 1, причем n = 1 или an − 1 = 0 и выполнено равенство: x = a0*(-2)0 + a1*(-2)1 + ... + an-1*(-2)n-1. Например, 3 в (-2)-ичной системе счисления представляется набором (1,1,1): действительно, 1*(-2)0+ 1*(-2)1+ 1*(-2)2= 1 - 2 + 4 = 3. В задаче предлагается перевести в (-2)-ичную систему счисления только одно число, но Соне стало интересно решение этой задачи в общем случае. После долгих раздумий она обратилась к вам за помощью. Помогите ей перевести заданное число в (-2)-ичную систему счисления. Формат файла входных данных: В единственной строке входного файла записано одно целое число x — число, которое Соня хочет представить в (-2)-ичной системе счисления (-1018<=x<=1018). Formally, writing a number in the (-2) -ary number system is a set of numbers a0, a1, ..., an - 1, each of which is equal to 0 or 1, and n = 1 or an - 1 = 0 and the equality holds: x = a0 * (- 2) 0 + a1 * (- 2) 1 + ... + an-1 * (- 2) n-1. For example, 3 in the (-2) -ary number system is represented by the set (1,1,1): indeed, 1 * (- 2) 0+ 1 * (- 2) 1+ 1 * (- 2) 2 = 1 - 2 + 4 = 3. In the problem, it is proposed to transfer only one number to the (-2) -ary number system, Output data file format: In the first line of the output file print the number n (n> = 1). On the second line of the output file, print n numbers a0, a1, separated by spaces. ... ... , an − 1 are the digits of the number x in the (-2) -ary number system (0 <= ai <= 1). If there are several answers, print any of them. Example: notation.in notation.out 3 3 1 1 1 -2 2 0 1

6th Sep 2020, 4:32 PM
машик_кошик
машик_кошик - avatar
2 Answers
+ 7
Can you write your question in English language . What Output u expecting. Your first mistake is in if condition if (x / 2 = 1) here you should write (==) in place of = . Second error in while loop here l value required error showing u have not write condition properly u should write like this while (x / 2 != 1). Where you inserting string here no memory is allocating.
6th Sep 2020, 6:05 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Hello
7th Sep 2020, 7:58 AM
машик_кошик
машик_кошик - avatar