FIFO Page Replacement algorithm in c
On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
code in C:#include<stdio.h> int main() { int i,j,n,a[50],frame[10],no,k,avail,count=0; printf("\nenter the length of the Reference string:\n"); scanf("%d",&n); printf("\n enter the reference string:\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("\n enter the number of Frames:"); scanf("%d",&no); for(i=0;i<no;i++) frame[i]= -1; j=0; printf("\tref string\t page frames\n"); for(i=1;i<=n;i++) { printf("%d\t\t",a[i]); avail=0; for(k=0;k<no;k++) if(frame[k]==a[i]) avail=1; if (avail==0) { frame[j]=a[i]; j=(j+1)%no; count++; for(k=0;k<no;k++) printf("%d\t",frame[k]); } printf("\n\n"); } printf("Page Fault Is %d",count); return 0; }output:-
enter the length of the Reference string: 20 enter the reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 enter the number of Frames:3 ref string page frames 7 7 -1 -1 0 7 0 -1 1 7 0 1 2 2 0 1 0 3 2 3 1 0 2 3 0 4 4 3 0 2 4 2 0 3 4 2 3 0 0 2 3 3 2 1 0 1 3 2 0 1 2 0 1 7 7 1 2 0 7 0 2 1 7 0 1 Page Fault Is 15 -------------------------------- Process exited after 38.24 seconds with return value 0 Press any key to continue . . .
0 comments: