二进制的转换

大家应该都会从十进制转到二进制吧,就是除2求余,然后从下往上写结果。
如图:
 但是c++代码怎么写呢,我才教大家一个简单的方法。先打好代码
#include
using namespace std;
int main(){

return 0;
}
在main函数上面打"std;"下面打:
int a[1001];
先int一个列表;
在mian函数下打上while循环:
int n,m = 0;
cin >> n;
while(n > 0){
a[m] = n % 2;
n = n / 2;
m++;
}
for(int i = 0; i <= m - 1; i++){ cout << a[m - i - 1]; } 最后代码
#include
using namespace std;
int a[1001];
int main(){
int n , m = 0;
cin >> n;
while(n > 0

二进制的转换最先出现在Python成神之路

版权声明:
作者:ht
链接:https://www.techfm.club/p/9743.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>