Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fix the errors in the following C code. #include int nofjobs; int nofmachines; struct s { int mId,duration; }; int main() { struct s machines[nofmachines],jobs[nofjobs];

Fix the errors in the following C code.

#include

int nofjobs;

int nofmachines;

struct s {

int mId,duration;

};

int main() {

struct s machines[nofmachines],jobs[nofjobs];

FILE *fptr;

fptr=fopen("file.txt","rb");

fread(jobs,sizeof(jobs),1,fptr);

fread(machines,sizeof(machines),1,fptr);

for (i=0;i

printf("Machine ID: %d duration: %d",jobs[i].mId,jobs[i].);

}

fclose(fptr);

}

// s1 -> machine 1

//s2->machine 2 , a[i]-> job[i] ,time-> time consumed,jobs sorted in descending order

// allocated one by one to the machine which is free.

long long ans=INT_MAX;

sort(a,a+n);

reverse(a,a+n);

int i=2;

int s1=machines[0];

int s2=machines[1];

long long time=min(s1,s2);

s1-=time;

s2-=time;

while(i

{

if(s1==0 && s2==0)

{

s1=a[i];

if(i+1

int c=min(s1,s2);

time+=c;

s1-=c;

s2-=c;

i+=2;

continue;

}

else

{

if(s1

s2=a[i];

int c=min(s1,s2);

time+=c;

s1-=c;

s2-=c;

i++;

}

}

assert(s1*s2==0);

ans = min(ans,time+max(s1,s2));

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago