Unimart is offering a dhamaka offer. Terms and conditions to gain the offer as follows: Unimart will provide a shopping bag which you can carry W weight at maximum load. (If you try to load more than W weight then it will fall on the ground and you will lose the offer forever) Unimart has N < 10 products with weight w1, w2, w3...etc. You can get only 1 product for each item. Input: W N maximum weight and number of products. Find the set of products and their sum so that you can use the maximum weight of your bag capacity. N integers represent weight product P1, P2....Pn. Output: Print selected products set and the sum of these products. Sample Input: 10 4 8 9 2 4 20 4 10 7 4 5 90 8 23 10 1 7 2 3 4 5 Sample Output: 8 2 Sum: 10 10 5 4 Sum: 19 23 10 1 2 3 4 5 7 Sum: 55 Output product set sequence doesn't matter but you have to find the optimal sum of weight so that maximizes the profit.
#include <stdio.h>
int main()
{
int W,N,i;
int sum=0;
printf("Enter the maximum weight: ");
scanf("%d",&W);
printf("Enter the values of N: ");
for(i=0;i<10;i++){
scanf("%d",&N);
sum=sum+N;
}
printf("%d",N);
printf(" Sum is: %d",sum);
if(W>sum){
printf("Overweight!, you lose the offer");
}
return 0;
}
Comments
Leave a comment