Program to implement FIFO Page replacement algorithm

    
/*Objective: implement FIFO Page replacement algorithm
   Author:Rahul kumar */

   #include <stdio.h>

#define max 100
int main()
{
  int i,j,k,no_of_pages,ref_str[max],no_of_frames,frame[max],avail,count=0;
  printf("\nEnter the total no of pages: ");
  scanf("%d",&no_of_pages);
  printf("\nEnter the Page No. OR Ref String: ");
  for(i=0;i< no_of_pages;i++)
  {
    scanf("%d",&ref_str[i]);
  }
  printf("\n Enter the total no. of frames: ");
  scanf("%d",&no_of_frames);
  for(i=0;i< no_of_frames;i++)
  {
    frame[i]=-1;  //for empty frame
  }
  j=0;
  printf("\tRef String\tFrames\n");
  for(i=0;i< no_of_pages;i++)
  {
    printf("%d\t\t",ref_str[i]);
    avail=0;
    for(k=0;k< no_of_frames;k++)
    {
      if(frame[k]==ref_str[i])    //to check frame is not empty
      avail=1;
    }
    if(avail==0)
    {
      
      
      frame[j]=ref_str[i];
      j=(j+1)%no_of_frames; 
      count++;
      for(k=0;k< no_of_frames;k++)
      printf("%d\t",frame[k]);
    
    }
    printf("\n");
  }
  printf("Page Fault is %d",count);
  return 0;
}      


Output:

Enter the total no of pages: 10

Enter the Page No. OR Ref String: 4
7
6
1
7
6
1
2
7
2

 Enter the total no. of frames: 3
        Ref String      Frames
4               4       -1      -1
7               4       7       -1
6               4       7       6
1               1       7       6
7
6
1
2               1       2       6
7               1       2       7
2
Page Fault is 6