Question: PLEASE FIND THE ERROR HERE and PLEASE PASTE THE CODE THANKYOU int tph, philname[20], status[20], howhung, hu[20], cho; main() { int i; clrscr(); printf( DINING

PLEASE FIND THE ERROR HERE and PLEASE PASTE THE CODE THANKYOU

int tph, philname[20], status[20], howhung, hu[20], cho; main()

{

int i; clrscr();

printf(" DINING PHILOSOPHER PROBLEM");

printf(" Enter the total no. of philosophers: ");

scanf("%d",&tph);

for(i=0;i

{

philname[i]=(i+1); status[i]=1;

}

printf("How many are hungry : ");

scanf("%d", &howhung);

if(howhung==tph)

{

printf( All are hungry.. Dead lock stage will occur);

printf( Exiting );

else{

for(i=0;i

{

printf(Enterphilosopher%dposition:,(i+1));

scanf(%d,&hu[i]);

status[hu[i]]=2;

}

do

{

printf("1.One can eat at a time \t2.Two can eat at a time \t3.Exit Enter your choice:");

scanf("%d", &cho);

switch(cho)

{

case 1: one();

break;

case 2: two();

break;

case 3: exit(0);

default: printf(" Invalid option..");

}

}while(1);

}

}

one()

{

int pos=0, x, i;

printf(" Allow one philosopher to eat at any time ");

for(i=0;i

{

printf(" P %d is granted to eat", philname[hu[pos]]);

for(x=pos;x

printf(" P %d is waiting", philname[hu[x]]);

}

}

two()

{

int i, j, s=0, t, r, x;

printf(" Allow two philosophers to eat at same time ");

for(i=0;i

{

for(j=i+1;j

{

if(abs(hu[i] - hu[j])>=1&& abs(hu[i] - hu[j])!=4)

{

printf(" combination %d ", (s+1));

t=hu[i];

r=hu[j];

s++;

printf(" P %d and P %d are granted to eat", philname[hu[i]], philname[hu[j]]);

for(x=0;x

{

if((hu[x]!=t)&&(hu[x]!=r))

printf(" P %d is waiting", philname[hu[x]]);

}

}

}

}

}

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!