Please debug the code below.Use C programming to solve the problem.Thanks       #include #include #include #include #include void one(void); void two(void); void exit(); int tph,philname[20],howhung[20],cho; // {} [] int main(void) { int i; printf("\n\nDINING PHILOSOPHER PROBLEM"); printf("\nEnter the total no. of philosophers: "); scanf("%d"); for (i=0;i=1 && abs(hu[i]-hu[j])!=tph-1) { printf("\n\n combination %d \n",(s+1)); t=hu[i]; r=hu[j]; s++; if(r-t==1)continue; printf("\nP %d and P %d are granted to eat",t,r); for(x=0;x

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please debug the code below.Use C programming to solve the problem.Thanks

 

 

 

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void one(void);
void two(void);
void exit();
int tph,philname[20],howhung[20],cho; // {} []

int main(void)
{
int i;
printf("\n\nDINING PHILOSOPHER PROBLEM");
printf("\nEnter the total no. of philosophers: ");
scanf("%d");
for (i=0;i<tph;i++)
{
philname[i] = (i+1);
status[i] =1;
}
printf("How many are hungry: ");
scanf("%d", &howhung);
if(howhung==tph)
{
printf("\nAll are hungry..\Dead lock stage will occur");
printf("\nExiting..");
}
else
{
for(i=0;i<howhung;i++)
{
printf("Enter philosopher %d position: ",(i+1));
scanf("%d", &hu[i]);
status[hu[i]]=2;

}
do
{
printf("\n\n1.One can eat at a time \t2.Two can eat at a time \t3.Exit\nEnter your choice:");
scanf("%d",&cho);
switch(cho)
{
case 1: two();
break;
case 2: one();
break;
case 3: exit(0);
default: printf("\nInvalid option..");
}
}
while(1);

}
}
void one(void)
{
int pos=0,x,i;
printf("\nAllow one philosopher to eat at any time\n");
for(i=0;i<howhung;i++,pos++)
{
printf("\nP %d is granted to eat",hu[pos]);
for(x=pos+1;x<howhung;x++)
printf("\nP %d is waiting",hu[x]);

}
}
void two(void)
{
int i,j,s=0,t,r,x;
printf("\nAllow two philosopher to eat at same time\n");
for(i=0;i<howhung;i++)
{
for(j=i+1;j<howhung;j++)
{
if(abs(hu[i]-hu[j])>=1 && abs(hu[i]-hu[j])!=tph-1)
{
printf("\n\n combination %d \n",(s+1));
t=hu[i];
r=hu[j];
s++;
if(r-t==1)continue;
printf("\nP %d and P %d are granted to eat",t,r);
for(x=0;x<howhung;x++)
{
if((hu[x]!=t)&&(hu[x]!=r))
printf("\nP %d is waiting",hu[x]);
}

}

}
}
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education