lesson 47

This commit is contained in:
Alexander Zhirov 2021-09-07 17:10:24 +03:00
parent e280a4648d
commit 4bebb5b445
1 changed files with 28 additions and 0 deletions

28
lesson_47/main.cpp Normal file
View File

@ -0,0 +1,28 @@
/*
* main.cpp
*
* Created on: 7 сент. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "Введите число от 0 до 255: ";
int n;
cin >> n;
cout << "Число " << n << " в двоичной системе счисления: ";
for (int i = 7; i >= 0; --i)
{
int degree = pow(2, i);
cout << (n >= degree) << (i == 4 ? " " : "");
if (degree <= n)
n -= degree;
}
return 0;
}