Question: I already have the C code for the following question. Please modify only the last part in the code so that I will get the

I already have the C code for the following question.

Please modify only the last part in the code so that I will get the output as 0.7 instead of 0.66 (round off 0.66 to 0.7)

The part in the code that has to be modified is kept in Bold to avoid confusion.

The Question is:

I already have the C code for the following question. Please modify

C code:

#include #include

void main() { int capacity, itemsno, curr_weight, item; int used[10]; float total_profit; int i; int weight[10]; int value[10]; scanf("%d", &capacity); scanf("%d", &itemsno); for (i = 0; i 0) { item = -1; for (i = 0; i (float) value[item] / weight[item]))) item = i; used[item] = 1; curr_weight -= weight[item]; total_profit += value[item]; if (curr_weight >= 0) printf("1.0 "); else { float item_percent = (int) ((1 + (float) curr_weight / weight[item]) * 100); printf("%.2f ", item_percent/100); total_profit -= value[item]; total_profit += (1 + (float)curr_weight / weight[item]) * value[item]; } } }

Input and Output for the given code:

only the last part in the code so that I will get

Please make changes in the code so that the output will be 1.0 1.0 0.7

Round off 0.66 to 0.7

****Please provide the correct code which results in correct output as specified. Only then Upvote will be given, or else I will downvote.

THANK YOU....

Write a C program to solve the fractional knapsack problem. For example, the weights and values of 3 divisible items are given in the table below. The capacity of the knapsack bag is 50. Find an optimal solution to maximize the value to weight ratio. Item Weight Value 1 10 $60 2 20 $100 3 30 $120 Note : Read knapsack capacity, number of items, weights of items and profits of items from the user. Print the solution. Round the solution to one fractional digit after decimal point. For example the solution for the above problem would be 1.0 1.0 0.7 For example: Input Result 50 1.0 1.0 0.7 3 10 20 30 60 100 120 50 3 10 20 30 60 100 120 1.0 1.0 0.66

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!