#include<stdio.h> #include<stdlib.h> int in[100], p[20], n, nf; void getData(); void getData() { printf("enter number of seq:"); scanf("%d", &n); printf("enter seq:"); for (int i = 0; i < n; i++) { scanf("%d", &in[i]); } printf("enter no of frames:"); scanf("%d", &nf); } int isHit(int x) { for (int i = 0; i < nf; i++) { if (x == p[i]) return 1; } return 0; } void display() { printf("status:\n"); for (int i = 0; i < nf; i++) if (p[i] != 9999) printf("%d ", p[i]); printf("\n"); } void fifo() { int pgfault = 0; for (int i = 0; i < nf; i++) p[i] = 9999; for (int i = 0; i < n; i++) { printf("for %d\n", in[i]); if (isHit(in[i]) == 0) { int k; for (k = 0; k < nf - 1; k++) p[k] = p[k + 1]; p[k] = in[i]; pgfault++; display(); } else { printf("page fault does not exist\n"); } } printf("no of pgfaults:%d", pgfault); } int main() { getData(); fifo(); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter