Google Search

Thursday, October 6, 2011

write a C program program to implement page replacement using FIFO algorithm


/* program to implement page replacement using FIFO algorithm*/
#include<stdio.h>
int re[30],p[10],i,j,n,nr,line=6,c=0,a1=0;
main()
{
          clrscr();
          printf(" enter length of reference string:");
          scanf("%d",&nr);
          printf(" enter reference string:");
          for(i=1;i<=nr;i++)
          {
                   scanf("%d",&re[i]);
          }
          printf(" \n enter number of frames:");
          fflush(stdin);
          scanf("%d",&n);
          for(i=1;i<=n;i++)
          p[i]=-1;
          for(i=1,j=1;i<=nr;i++)
          {
                   a1=0;
                   if(j>n)
                   j=1;
                   for(c=1;c<=n;c++)
                   if(re[i]==p[c])
                   a1++;
                   if(a1==0)
                   {
                             p[j]=re[i];
                             j++;
                   }
                   display(n,p,i);
          }
          printf("\n");
          getch();
}

display(int no,int p[],int i)
{
          int k;
          if(i==1)
          {
                   printf("\t\t\t");
                   for(k=1;k<=no;k++)
                   printf("_ _");
          }
          printf("\n%8d",re[i]);
          gotoxy(25,line++);
          for(k=1;k<=no;k++)
          {
                   printf("|");
                   printf("_");
                   if(p[k]!=-1)
                   printf("%d",p[k]);
                   else
                   printf(" ");
                   printf("_");
          }
          printf("|");
}

0 comments:

Post a Comment