Program7 Knapsack C D Greedy
Program7 Knapsack C D Greedy
#include <stdlib.h>
typedef struct
{ int p; // Profit
int w; // Weight
/* main function */
int main()
printf("Items: ");
printf("Capacity: ");
printf("Profit: ");
scanf("%d", &a[i].p);
printf("Weight: ");
scanf("%d", &a[i].w);
}
// Sort items by profit-to-weight ratio in descending order using bubble sort
I t = a[j];
a[j + 1] = t;
} else {
printf("Item\tWeight\tProfit\tFraction\n");
} else {
printf("Item\tWeight\tProfit\tFraction\n");
return 0;
}