printf输出⼆进制printf输出⼆进制
题意:
输出0到31的⼆进制数,要求前导零,保持位数为五位
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
for(int i = 0 ; i < 32 ; i ++){
char s[10] = {0,0,0,0,0,0,0,0,0,0};
itoa(i, s, 2);
if(strlen(s) < 5) {
for(int i = 5 - strlen(s) ; i > 0 ; i --) cout << "0" ;printf输出格式补0
printf("%s",s);
}
else printf("%s",s);
cout << endl ;
}
return 0;
}