-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8.c
46 lines (40 loc) · 1.09 KB
/
8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
int main(int argc, char const *argv[])
{
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;
int s[10], fno[10][20];
printf("\nEnter the memory size -- ");
scanf("%d", &ms);
printf("\nEnter the page size -- ");
scanf("%d", &ps);
nop = ms / ps;
printf("\nThe no. of pages available in memory are -- %d ", nop);
printf("\nEnter number of processes -- ");
scanf("%d", &np);
rempages = nop;
for (i = 1; i <= np; i++)
{
printf("\nEnter no. of pages required for p[%d]-- ", i);
scanf("%d", &s[i]);
if (s[i] > rempages)
{
printf("\nMemory is Full");
break;
}
rempages = rempages - s[i];
printf("\nEnter pagetable for p[%d] --- ", i);
for (j = 0; j < s[i]; j++)
scanf("%d", &fno[i][j]);
}
printf("\nEnter process no., pagenumber, offset -- ");
scanf("%d %d %d", &x, &y, &offset);
if (x > np || y >= s[i] || offset >= ps)
printf("\nInvalid Process or Page Number or offset");
else
{
pa = fno[x][y] * ps + offset;
printf("\nThe Physical Address is : %d", pa);
}
printf("\n");
return 0;
}