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); }
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);
}
Step by step
Solved in 3 steps with 1 images
- Recommended textbooks for youMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,