Last active
February 17, 2020 02:52
-
-
Save yudegaki/31b516395109494a64558c214daad19c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//「000」〜「111」を出力するプログラム | |
#include<bits/stdc++.h> | |
using namespace std; | |
void printBit(int bit,int digit){//bitを表示する数字と何桁まで表示するかを引数で指定 | |
string s; | |
for(int i = 0;i < digit;i++){ | |
if(bit & (1LL << i)){//bitが立っていたら | |
s = "1" + s; | |
} | |
else { | |
s = "0" + s; | |
} | |
} | |
cout<<s<<endl; | |
} | |
int main(){ | |
int n = 3;//今回は3桁なので | |
for(int i = 0; i < (1LL << n)/*pow(2,n)と同義*/ ;i++){ | |
printBit(i,n); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment