cl1p.net - The internet clipboard
Login/Sign Up
cl1p.net/abcd
cl1p.net/abcd
Login/Sign Up
This cl1p will be deleted in in 57 days.
Copy
IMPORTANT: bit.ly/m/today#include<stdio.h> int main(){ int f,p; printf("Enter the number of frames: "); scanf("%d",&f); printf("Enter the number of pages: "); scanf("%d",&p); int page[p]; printf("Enter page reference string:\n"); for(int i=0;i<p;i++){ scanf("%d",&page[i]); } int frame[f], time[f]; int count = 0; int hits = 0, misses = 0; for(int i=0;i<f;i++) { frame[i] = -1; time[i] = 0; } printf("\nStep-by-step execution:\n"); for(int i=0;i<p;i++){ int found = 0; printf("\nPage %d -> ", page[i]); for(int j=0;j<f;j++){ if(frame[j] == page[i]){ count++; time[j] = count; found = 1; hits++; printf("HIT\n"); break; } } if(!found){ int min = time[0], pos = 0; for(int j=1;j<f;j++){ if(time[j] < min){ min = time[j]; pos = j; } } frame[pos] = page[i]; count++; time[pos] = count; misses++; printf("MISS\n"); } printf("Frames: "); for(int j=0;j<f;j++){ if(frame[j] != -1) printf("%d ", frame[j]); else printf("- "); } printf("\n"); } printf("\nTotal Hits: %d", hits); printf("\nTotal Misses (Page Faults): %d\n", misses); return 0; }