Space for google add

Implement FIFO.

 FIFO


#include <stdio.h>

int n,i,j,k,no,a[100],frame[10],count=0,avail;

int main()

{

printf("\n Enter how many pages");

scanf("%d",&n);

printf("\n Enter the pages:");

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;

}

k=0;

printf("\n FIFO algorithm is:\n");

printf("ref str\t frame\n"); 

for(i=1;i<=n;i++)

{

printf("%d \t\t",a[i]);

avail=0;

for(j=0;j<no;j++)

{

if(frame[j]==a[i])

{

avail=1;

}

}

if(avail==0)

{

frame[k]=a[i];

count++;

k=(k+1)%no;

for(j=0;j<no;j++)

{

printf("%d\t",frame[j]);

}

printf("Y");

}else

{

for(j=0;j<no;j++)

{

printf("%d\t",frame[j]);

}

printf("N");

}

printf("\n");

}

printf("\n page faults are:%d\n",count);

}


Post a Comment

0 Comments