Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Alexander Zhirov | c4761a5ee6 | |
Alexander Zhirov | 4bebb5b445 |
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
Loading…
Reference in New Issue