Implementation of page replacement policy

/*
* Title: Implementation of page replacement policy
* Name: Akshay Thakare
* Roll No: 6790
*/

#include
int main()
{
    int a[50],x[3]={-1,-1,-1},i,j,k,n,h=0,f=0,flag=0;
	printf("Enter no of pages\n");
	scanf("%d",&n);
	printf("Enter page nos\n");
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	{
		flag=0;
		for(j=0;j<3;j++)
	 	{
			if(a[i]!=x[j]&&x[j]==-1)
			{
				x[j]=a[i];
                j=30;
				for(k=0;k=0)
						printf("%d\t",x[k]);
				printf("\n");
			}
			else if(a[i]==x[j])
			{
				h++;
                j=30;
				for(k=0;k=0)
						printf("%d\t",x[k]);
				printf("HIT\n");
			}
			else if(a[i]!=x[j]&&x[j]>=0)
			{
				flag++;
				if(flag==3)
				{
					x[f%3]=a[i];
					for(k=0;k=0)
							printf("%d\t",x[k]);
					printf("FAULT\n");
					f++;					
				} 	
			}
		}	
	}
	printf("\nNo of Hits   = %d",h);
	printf("\nNo of Faults = %d\n",f);
	return 0;
}

/*
OUTPUT
Enter no of pages
12
Enter page nos
2 3 2 1 5 2 4 5 3 2 5 2
2    
2	3	
2	3	HIT
2	3	1	
5	3	1	FAULT
5	2	1	FAULT
5	2	4	FAULT
5	2	4	HIT
3	2	4	FAULT
3	2	4	HIT
3	5	4	FAULT
3	5	2	FAULT

No of Hits   = 3
No of Faults = 6

*/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s