C++
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
22
1
2
using std::cout;
3
using std::endl;
4
int main(void) {
5
int arr[] = {0,1,2,3,4,5,6,7,8,9,10};
6
int opsize = sizeof(arr) / sizeof(*arr);
7
int n = opsize;
8
9
for (int counter = 1; counter < opsize; counter++)
10
{
11
for (int j = 0; j < n; j++)
12
{
13
/* Check if jth bit in the counter is set
14
If set then print jth element from arr[] */
15
if (counter & (1<<j))
16
cout << arr[j] << " ";
17
}
18
cout << endl;
19
}
20
}
21
22
$ g++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.73.0/gcc-10.1.0/include -std=gnu++2a
Start
0 1 0 1 2 0 2 1 2 0 1 2 3 0 3 1 3
0
Finish