i was on to writing the program of subset sum problem in c. The program run just fine when number of element in the array <=30 , if number of element in the array are > 30 , program doesn't work correctly and gives the exection "An unhandled exception of type 'System.DivideByZeroException' occurred"
Source Code:
 #include<stdio.h>
  #include<math.h>
 int power(int a,int b)
{
    int i=2;
    int base=2;
    if(b==0)
        return 1;
    if(b==1)
        return a;
    else
    while(i<=b)
    {
        a=a*base;
        i++;
    } 
    return a;
}
int main()
{    
    int n,p,q,s,sum;
    n=30;       // no. of element in the array. 
    p=0;
    q=0;
    sum=0;
    int aa[30]={3,2,5,1,9,4,5,1,33,23,87,132,74,63,19,2,32,75,17,32,93,34,4,54,12,95,34,82,75,83};
    s=power(2,n);     // no. of subsets in the set
    while(p<=s)
    {        
         while(q<n)
         {
             if(power(2,q)<=(p%power(2,q+1)) && (p%power(2,q+1))<=(power(2,q+1)-1) )
                 sum=sum+aa[(n-1)-q];
             q++;
         }
          if(sum==16)
         {
             printf("Found the SUM at row %d",p);
         }
          sum=0;
         p++;
         q=0;
    }
         printf("Not Found");
} 

powermethod just to do1 << n?