#include <stdio.h>
int main()
{
int referenceString[10], pageFaults = 0, m, n, s, pages, frames;
printf("
Enter the number of Pages: ");
scanf("%d", &pages);
printf("
Enter reference string values:
");
for( m = 0; m < pages; m++)
{
printf("Value No. [%d]: ", m + 1);
scanf("%d", &referenceString[m]);
}
printf("
What are the total number of frames: ");
{
scanf("%d", &frames);
}
int temp[frames];
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(referenceString[m] == temp[n])
{
s++;
pageFaults--;
}
}
pageFaults++;
if((pageFaults <= frames) && (s == 0))
{
temp[m] = referenceString[m];
}
else if(s == 0)
{
temp[(pageFaults - 1) % frames] = referenceString[m];
}
printf("
");
for(n = 0; n < frames; n++)
{
printf("%d ", temp[n]);
}
}
printf("
Total Page Faults: %d
", pageFaults);
return 0;
}
#include <stdio.h>
int main()
{
int referenceString[10], pageFaults = 0, m, n, s, pages, frames;
printf("
Enter the number of Pages: ");
scanf("%d", &pages);
printf("
Enter reference string values:
");
for( m = 0; m < pages; m++)
{
printf("Value No. [%d]: ", m + 1);
scanf("%d", &referenceString[m]);
}
printf("
What are the total number of frames: ");
{
scanf("%d", &frames);
}
int temp[frames];
for(m = 0; m < frames; m++)
{
temp[m] = -1;
}
for(m = 0; m < pages; m++)
{
s = 0;
for(n = 0; n < frames; n++)
{
if(referenceString[m] == temp[n])
{
s++;
pageFaults--;
}
}
pageFaults++;
if((pageFaults <= frames) && (s == 0))
{
temp[m] = referenceString[m];
}
else if(s == 0)
{
temp[(pageFaults - 1) % frames] = referenceString[m];
}
printf("
");
for(n = 0; n < frames; n++)
{
printf("%d ", temp[n]);
}
}
printf("
Total Page Faults: %d
", pageFaults);
return 0;
}