Answer to Question #241081 in C for FAJLA

Question #241081

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.


1
Expert's answer
2021-09-24T00:03:57-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS