Ask coding questions

← Back to all posts
finding largest subarray with sum of elements in it is 0
srujith1 (0)

#include <stdio.h>
#include<stdlib.h>
void popout (int a[100], int q, int n,int j)
{ int z; z=n;
for (int o = q; o < n - 1; o++)
{
a[o] = a[o + 1]; //deletes one number
}
int g=j;
if(g!=1){ z--; //function calls recursively till we are
// deleting only one number
for(int i=0;i<n;i++){
popout(a,a[i],z,g-1); // after deleting one number again
//again runs a loop to delete other
//number from already deleted array
}
g--;
}
}

int main ()
{
int n;int f;
int a[100];
int b[100];
printf ("enter number of elemnts");
scanf ("%d", &n);
printf ("enter elements");
for (int i = 0; i < n; i++)
scanf ("%d", &a[i]);
for (int i = 0; i < n; i++)
b[i] = a[i];
for (int j = 1; j < n; j++)
a[0] = a[0] + a[j];
if (a[0] == 0)
printf ("%d", n);
for (int i = 0; i < n; i++)
a[i] = b[i];
/ pop out number by number /
for(int p=1;p<n;p++){ //p:number of elements to be deleted at onece
for(int i=0;i<n;i++){
popout(a,a[i],n,p);
for(int g=1;g<n-1;g++){
a[0]+=a[g];
}
if(a[0]==0)
{
printf("%d",n-p); exit;
}
else{
for(int i=0;i<n;i++)
a[i]=b[i];
}

}

}

return 0;

}

this is my code..... I could not find any errors in it anyone please tell me where my program is getting wrong