Knapsack problem

what is wrong in the code ?

check your input
int wt[]={40,30,20,100};
int c=7;
capacity of bag is 7 and weigts are more than 20

the mistake in code is set inc=0
otherwise garbage is compare with exc if(wt[n-1]>c)

1 Like

thanks it is running fine