Knapsack-N
Knapsack-N
#include<stdio.h>
#include<conio.h>
tp = 0;
rcap = capacity;
if (i < n)
x[i] = rcap / weight[i];
tp = tp + (x[i] * profit[i]);
void main()
{
float weight[20], profit[20], ratio[20], capacity;
int num,i,j;
float temp;
clrscr();
printf("Enter the no. of items : ");
scanf("%d",&num);
printf("\nEnter the capacity of knapsack : ");
scanf("%f",&capacity);
OUTPUT :
The result vector is = {1.00, 1.00, 1.00, 1.00, 1.00, 0.67, 0.00}