Skip to content

Instantly share code, notes, and snippets.

@rahulkmr
Created February 7, 2010 06:38
Show Gist options
  • Save rahulkmr/297257 to your computer and use it in GitHub Desktop.
Save rahulkmr/297257 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int equi(int a[], int n ) {
int i, j;
long int sum = 0;
int **sum_list = calloc(sizeof *sum_list, n);
assert(sum_list != NULL);
for (i = 0; i < n; i++) {
sum_list[i] = calloc(sizeof *sum_list[i], n);
assert(sum_list[i] != NULL);
}
for (i = 0; i < n - 1; i++) {
sum_list[i][i] = sum = a[i];
for (j = i + 1; j < n; j++) {
sum += a[j];
sum_list[i][j] = sum;
}
}
for (i = 1; i < n - 1; i++)
if (sum_list[0][i-1] == sum_list[i+1][n-1])
printf("%d\n", i);
}
int main(void)
{
int a[] = {-7, 1, 5, 2, -4, 3, 0};
equi(a, 7);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment