0% found this document useful (0 votes)
13 views3 pages

FIFO Page Replacement Algorithm in C

The document contains a C program that simulates a page replacement algorithm. It prompts the user to input the number of pages, a reference string, and the number of frames, then calculates and displays the frames after each page request along with the total number of page faults. The output shows the frames' state after processing each page and concludes with the total number of page faults encountered.

Uploaded by

vaishnavak77
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

FIFO Page Replacement Algorithm in C

The document contains a C program that simulates a page replacement algorithm. It prompts the user to input the number of pages, a reference string, and the number of frames, then calculates and displays the frames after each page request along with the total number of page faults. The output shows the frames' state after processing each page and concludes with the total number of page faults encountered.

Uploaded by

vaishnavak77
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<stdio.

h>

Int main()

int n,f,fr[20],p[50],rep=0,found,fi=0;

int i,k;

printf("Enter the number of pages:");

scanf("%d",&n);

printf("Enter the reference string:");

for(i=0;i<n;i++)

scanf("%d",&p[i]);

printf("Enter the frame number:");

scanf("%d",&f);

for(i=0;i<f;i++)

fr[i]=-1;

printf("\n\nPages\tFrames\n\n");

for(i=0;i<n;i++)

printf("%d\t\t",p[i]);

found=0;

for(k=0;k<f;k++)

if(p[i]==fr[k])

found=1;

break;

if(!found)

fr[fi]=p[i];

rep++;
fi=(fi+1)%f;

for(k=0;k<f;k++)

printf("%d\t",fr[k]);

printf("\n");

printf("\n\nNumber of page fault:%d\n",rep);

OUTPUT

Enter the number of pages:20

Enter the reference string:7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

Enter the frame number:3

Pages Frames

7 7 -1 -1

0 7 0 -1

1 7 0 1

2 2 0 1

3 2 3 1

0 2 3 0

4 4 3 0

2 4 2 0

3 4 2 3

0 0 2 3

1 0 1 3
2 0 1 2

7 7 1 2

0 7 0 2

1 7 0 1

Number of page fault:15

=== Code Execution Successful ===

You might also like