#include <iostream> #include <cmath> using namespace std; void printPowerSet(string str) { int n = str.length(); int powSize = pow(2, n); for(int counter = 0; counter < powSize; counter++) { for(int j = 0; j < n; j++) { if((counter & (1 << j)) != 0) cout<<str[j]; } cout<<endl; } } int main() { string s = "abc"; printPowerSet(s); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter