Question: #include #include #include #include #define MAX _ LINE _ LENGTH 1 0 2 4 #define MAX _ LABEL _ LENGTH 1 0 0 int max
#include
#include
#include
#include
#define MAXLINELENGTH
#define MAXLABELLENGTH
int maxint a int b;
int countLinesFILE file;
void parseItemsFILE file char labels int val int wt;
int knapsackint W int wt int val, int n
int withoutItem, withItem;
if n W
return ;
n;
if wtn W
return knapsackW wt val, n;
else
withoutItem knapsackW wt val, n;
withItem valn knapsackW wtn wt val, n;
return maxwithItem withoutItem;
int mainint argc, char argv
FILE file;
int count, i W maximumValue;
int valwt;
char labels;
if argc
printfUsage: s #include
#include
#include
#include #include
#include
#include
#include
#define MAXLINELENGTH
#define MAXLABELLENGTH
int maxint a int b;
int countLinesFILE file;
void parseItemsFILE file char labels int val int wt;
int knapsackint W int wt int val, int n
int withoutItem, withItem;
if n W
return ;
n;
if wtn W
return knapsackW wt val, n;
else
withoutItem knapsackW wt val, n;
withItem valn knapsackW wtn wt val, n;
return maxwithItem withoutItem;
int mainint argc, char argv
FILE file;
int count, i W maximumValue;
int valwt;
char labels;
if argc
printfUsage: s
argv;
return ;
file fopenargvr;
if file
perrorError opening file";
return ;
count countLinesfile;
val malloccount sizeofint;
wt malloccount sizeofint;
labels malloccount sizeofchar;
for i ; i count; i
labelsi mallocMAXLABELLENGTH sizeofchar;
parseItemsfile labels, val, wt;
fclosefile;
printfItems available:
;
for i ; i count; i
printfItem d: s Value: d Weight: d
i labelsi vali wti;
maximumValue knapsackW wt val, count;
printf
Maximum weight capacity of the knapsack: d
W;
printfMaximum value that can be accommodated: d
maximumValue;
for i ; i count; i
freelabelsi;
freelabels;
freeval;
freewt;
return ;
int maxint a int b
return a b a : b;
int countLinesFILE file
int lines ;
char lineMAXLINELENGTH;
while fgetsline sizeofline file
lines;
rewindfile;
return lines;
void parseItemsFILE file char labels int val int wt
char lineMAXLINELENGTH;
char token;
int index ;
while fgetsline sizeofline file
token strtokline;
strcpylabelsindex token;
token strtokNULL;
valindex atoitoken;
token strtokNULL;
wtindex atoitoken;
index;
How to parallelize this code using OpenMP?", argv;
return ;
file fopenargvr;
if file
perrorError opening file";
return ;
count countLinesfile;
val malloccount sizeofint;
wt malloccount sizeofint;
labels malloccount sizeofchar;
for i ; i count; i
labelsi mallocMAXLABELLENGTH sizeofchar;
parseItemsfile labels, val, wt;
fclosefile;
printfItems available:
;
for i ; i count; i
printfItem d: s Value: d Weight: d
i labelsi vali wti;
maximumValue knapsackW wt val, count;
printf
Maximum weight capacity of the knapsack: d
W;
printfMaximum value that can be accommodated: d
maximumValue;
for i ; i count; i
freelabelsi;
freelabels;
freeval;
freewt;
return ;
int maxint a int b
return a b a : b;
int countLinesFILE file
int lines ;
char lineMAXLINELENGTH;
while fgetsline sizeofline file
lines;
rewindfile;
return lines;
void parseItemsFILE file char labels int val int wt
char lineMAXLINELENGTH;
char token;
int index ;
while fgetsline sizeofline file
token strtokline;
strcpylabelsindex token;
token strtokNULL;
valindex atoitoken;
token strtok
