Playground
#include <iostream> #include <string> using namespace std; int main() { int N; cin >> N; //(1 << N) e ednakvo na 2^N for (int i=0; i < (1 << N); i++) { string current = ""; for (int j=0; j < N; j++) { //proveri dali j-tiot bit (gledano od pozadi) e 1 if (((1 << j) & i) != 0) { char ch = ('A' + j); current += ch; } } //otpechati go tekovnoto podmnozhestvo cout << current << endl; } return 0; }
Input data
Program output
3
Execute
Language: ????????? | Memory: ???? KB | Time: ??? ms
Nothing has been executed, yet!