#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,l,page[10],buf,buff[10],pagefault,num,temp,flag=1;
printf("\n Enter the number of paging sequence do u wanna enter:");
scanf("%d",&num);
printf("\n\n Enter the paging sequence:");
for(i=0;i<num;i++)
{
printf("\n page %d.",i+1);
scanf("%d",&page[i]);
}
printf("\n\n Enter the buffer size:");
scanf("%d",&buf);
for(j=0;j<buf;j++)
{
buff[j]=0;
}
pagefault=0;
k=0;
flag=1;
for(i=0;i<num;i++)
{
flag=1;
for(j=0;j<buf;j++)
{
if(buff[j]==page[i])
{
flag=0;
break;
}
}
j=0;
if(flag==0)
{
continue;
}
else
{
if(k <buf)
{
buff[k]=page[i];
k++;
pagefault++;
printf("\n Now Pages Are:");
for(l=0;l<buf;l++)
{
if(buff[l]!=0)
{
printf(" %d",buff[l]);
}
}
continue;
}
for(j=0;j<buf-1;j++)
{
temp=buff[j+1];
buff[j+1]=buff[j];
buff[j]=temp;
}
buff[buf-1]=page[i];
pagefault++;
printf("\n Now Pages Are:");
for(l=0;l<buf;l++)
{
if(buff[l]!=0)
{
printf(" %d",buff[l]);
}
}
}
}
printf("\n\n\t Hence the page faults are=%d",pagefault);
getch();
return 0;
}
Gurpreet Singh
No comments:
Post a Comment