Please make some changes in the code and make it unique #include   int main()  {      // P0, P1, P2, P3, P4 are the Process names here         int n, m, i, j, k,p,c=0;      n = 3;       m = 3;      int ch=1;     int adneed[3]={0};     int alloc[3][3] = { { 0, 0, 1 }, // P0    // Allocation Matrix                          { 3, 2, 0 }, // P1                          { 2, 1, 1 } // P2                           };         int max[3][3] = { { 8, 4, 3 }, // P0    // MAX Matrix                        { 6, 2, 0 }, // P1                        { 3, 3, 3 } // P2                        };          int avail[3] = { 3, 2, 2 };                  while(ch!=0)     {     printf("Enter process number\n");     scanf("%d",&p);     printf("Enter requirements of process p%d\n",p);     for(i=0;i<3;i++)     {     scanf("%d",&adneed[i]);     max[p][i]=max[p][i]+adneed[i];              //update MAX with additional requirements     }     printf("Is there any process request ?:(0/1)\n");     scanf("%d",&ch);     };    printf("The new Max matrix is:\n");    for(i=0;i<3;i++)    {        for(j=0;j<3;j++)        {            printf("%d ",max[i][j]);        }        printf("\n");    }                    int f[n], ans[n], ind = 0;      for (k = 0; k < n; k++) {          f[k] = 0;      }      int need[n][m];      for (i = 0; i < n; i++) {          for (j = 0; j < m; j++)              need[i][j] = max[i][j] - alloc[i][j];      }      int y = 0;      for (k = 0; k < 3; k++) {          for (i = 0; i < n; i++) {              if (f[i] == 0) {                     int flag = 0;                  for (j = 0; j < m; j++) {                      if (need[i][j] > avail[j]){                          flag = 1;                           break;                      }                  }                     if (flag == 0) {                      ans[ind++] = i;                      c++;                     for (y = 0; y < m; y++)                          avail[y] += alloc[i][y];                      f[i] = 1;                  }              }          }      }    if(c==3)   {     printf("Following is the SAFE Sequence\n");      for (i = 0; i < n -1; i++)          printf(" P%d ->", ans[i]);      printf(" P%d", ans[n - 1]);    }   else   {       printf("No safe sequence\n");   }     return (0);  }

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 make some changes in the code and make it unique

#include <stdio.h> 
int main() 

    // P0, P1, P2, P3, P4 are the Process names here 
  
    int n, m, i, j, k,p,c=0; 
    n = 3;  
    m = 3; 
    int ch=1;
    int adneed[3]={0};
    int alloc[3][3] = { { 0, 0, 1 }, // P0    // Allocation Matrix 
                        { 3, 2, 0 }, // P1 
                        { 2, 1, 1 } // P2 
                         }; 
  
    int max[3][3] = { { 8, 4, 3 }, // P0    // MAX Matrix 
                      { 6, 2, 0 }, // P1 
                      { 3, 3, 3 } // P2 
                      };  
  
    int avail[3] = { 3, 2, 2 }; 
    
    
      while(ch!=0)
    {
    printf("Enter process number\n");
    scanf("%d",&p);
    printf("Enter requirements of process p%d\n",p);
    for(i=0;i<3;i++)
    {
    scanf("%d",&adneed[i]);
    max[p][i]=max[p][i]+adneed[i];              //update MAX with additional requirements
    }
    printf("Is there any process request ?:(0/1)\n");
    scanf("%d",&ch);
    };
   printf("The new Max matrix is:\n");
   for(i=0;i<3;i++)
   {
       for(j=0;j<3;j++)
       {
           printf("%d ",max[i][j]);
       }
       printf("\n");
   }
    
    
    
    int f[n], ans[n], ind = 0; 
    for (k = 0; k < n; k++) { 
        f[k] = 0; 
    } 
    int need[n][m]; 
    for (i = 0; i < n; i++) { 
        for (j = 0; j < m; j++) 
            need[i][j] = max[i][j] - alloc[i][j]; 
    } 
    int y = 0; 
    for (k = 0; k < 3; k++) { 
        for (i = 0; i < n; i++) { 
            if (f[i] == 0) { 
  
                int flag = 0; 
                for (j = 0; j < m; j++) { 
                    if (need[i][j] > avail[j]){ 
                        flag = 1; 
                         break; 
                    } 
                } 
  
                if (flag == 0) { 
                    ans[ind++] = i; 
                    c++;
                    for (y = 0; y < m; y++) 
                        avail[y] += alloc[i][y]; 
                    f[i] = 1; 
                } 
            } 
        } 
    } 
  if(c==3)
  {
    printf("Following is the SAFE Sequence\n"); 
    for (i = 0; i < n -1; i++) 
        printf(" P%d ->", ans[i]); 
    printf(" P%d", ans[n - 1]); 
  }
  else
  {
      printf("No safe sequence\n");
  }
    return (0); 
}

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
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