Skip to content

Instantly share code, notes, and snippets.

@ofx
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofx/11355305 to your computer and use it in GitHub Desktop.
Save ofx/11355305 to your computer and use it in GitHub Desktop.
#include <math.h>
#include <stdio.h>
int S[] = {-7, -3, -2, 5, 8};
int main()
{
unsigned int i, n, a, j, nn, ui;
n = pow(2, sizeof(S) / sizeof(int)) - 1;
ui = sizeof(S) / sizeof(int);
for (i = 0 ; i <= n ; nn = ++i)
{
a = 0;
for (j = 0 ; j < ui ; ++j, nn >>= 1)
{
a += (nn & 0x1) * S[j];
}
if (a == 0)
{
printf("Sum (at %i)\n", i);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment