mask = 0; mask < (1 << n); ++mask
).1 << i
.#include <iostream>
using namespace std;
int main()
{
int const n = 3;
int intArray[n];
int sum;
for (int i = 0; i < n; i++)
{
cin >> intArray[i];
}
for (int mask = 0; mask < (1 << n); ++mask)
{
sum = 0;
for (int i = 0; i < n; i++)
{
if (mask & (1 << i))
{
sum = sum + intArray[i];
}
}
cout << sum <<" ";
}
return 0;
}