Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

=+What needs to be said first?

Answered: 1 week ago