You are on page 1of 58

ROUND ROBIN SCHEDULING

#include<stdio.h>
#include<conio.h>
void main()
{
int b=1,n,e[50],q,i,j,rt[50],ct[50]={0},tot=0,wt=0,await[50]={0},sum=0;
float twait=0.0,avg=0.0,through,turn;
clrscr();
printf("\nEnter No.of process: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\nEnter the exe.time : ");
scanf("%d",&e[i]);
rt[i]=e[i];
tot+=e[i];
sum=sum+e[i];
}
printf("\nEnter the time/quantum slice : ");
scanf("%d",&q);
while(tot>wt)
{
printf("\nCycle %d :",b);
for(i=1;i<=n;i++)
{
if((rt[i]>q)&&(ct[i]<e[i]))
{
rt[i]-=q;
ct[i]+=q;
printf("\nRemaining time of process %d = %d",i,rt[i]);
printf("\ncompletion time of procss %d = %d",i,ct[i]);
wt+=q;
}
else if(e[i])
{
printf("\nProcess %d completed....",i);
await[i]=wt-ct[i];
wt+=rt[i];

e[i]=0;
}
}
b++;
}
for(i=1;i<=n;i++)
{
printf("\nWaiting time of process %d = %d",i,await[i]);
twait+=await[i];
}
printf("\nTotal waiting time of %d process is = %f",n,twait);
avg=twait/n;
printf("\nAVERAGE WAITING TIME = %f",avg);
turn=sum+twait;
printf("\nTHE TURN AROUND TIME :%f",turn);
through=turn/n;
printf("\nTHE THROUGHPUT IS:%f",through);
getch();
}

SWAPPING WITHOUT USING TEMPROVARY VARIABLE


echo "Enter the two numbers"
read a b
echo "Before swapping"

echo "A= $a B= $b"


a=`expr $a + $b`
b=`expr $a - $b`
a=`expr $a - $b`
echo "A= $a B= $b"
OUTPUT:
Enter two Numbers
10 20
Before Swapping
A=10 B=20
After Swapping
A=20 B=10

FIBONACCI SERIES
echo "Enter the limit:"
read n
echo "The fibonacci series is"
a=-1
b=1
i=0
while [ $i -lt $n ]
do

c=`expr $a + $b`
a=$b
b=$c
echo "$c"
i=`expr $i + 1`
done
OUTPUT:
Enter the limit
5
The Fibonacci Series is
0
1
1
2
3

FIRST COME FIRST SERVED SCHEDULING


#include<iostream.h>
#include<conio.h>
void main()
{
int t[100],wait[100],n,i,tot[100],sumw=0,sumt=0;
float avgw,avgt;

clrscr();
cout<<"\n enter the no of process:";
cin>>n;
cout<<"\n enter the process time:";
for(i=1;i<=n;i++)
{
cin>>t[i];
}
wait[1]=0;
for(i=2;i<=n;i++)
wait[i]=wait[i-1]+t[i-1];
tot[i]=t[i]+wait[i];
for(i=1;i<=n;i++)
tot[i]=t[i]+wait[i];
for(i=1;i<=n;i++)
{
sumw+=wait[i];
sumt+=tot[i];
}
avgw=(float)sumw/n;
avgt=(float)sumt/n;
clrscr();
cout<<"\n\t\t\tFCFS\n";

cout<<"\n-----------------------------------------------------------------\n";
cout<<"\n process\texetime\twait time\tturn time";
cout<<"\n--------------------------------------------------------------\n";
for(i=1;i<=n;i++)
cout<<"\np"<<i<<"\t\t"<<t[i]<<"\t\t"<<wait[i]<<"\t\t"<<tot[i];
cout<<"\n---------------------------------------------------------------\n";
cout<<"\navg waiting time:"<<avgw;
cout<<"\navg turn arounnd time:"<<avgt;
getch();
}
OUTPUT:
Enter the process:4
Enter the process time:3
6
4
2
FCFS
-----------------------------------------------------------------------------------------------------------process
Exe time
Wait time
Turn time
-----------------------------------------------------------------------------------------------------------P1
P2

P3
P4
-----------------------------------------------------------------------------------------------------------Avg waiting time:6.25
Avg turn around time:10
3
6
4
2
0
3
9
13
SHORTEST JOB FIRST SCHEDULING
#include<stdio.h>
#include<conio.h>
void main()
{
int a[30],i,j,t,c[30],b[30],n;
float p=0,awt=0,att=0,tt=0,wt=0;
clrscr();
printf("enter process:");
scanf("%d",&n);

printf("enter the exe time:");


for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(a[j]>a[i])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
printf("\n\t\t\tSJF\n");
printf("\n-----------------------------------------------------------");
printf("\nprocess\texe.time\twaittime\tturnntime");
printf("\n-----------------------------------------------------------");
for(i=1;i<=n;i++)
{
wt=wt+p;
tt=tt+a[i];
awt=awt+wt;
att=att+tt;

p=a[i];
printf("\np%d\t%d\t\t%f\t%f",n,a[i],wt,tt);
}
printf("\n-------------------------------------------------------\n");
printf("\navg wait time:%f",awt/n);
printf("\navg turn time:%f",att/n);
getch();
}
OUTPUT:
Enter process:4
Enter the exe time:3
6
4
2
SJF
-----------------------------------------------------------------------------------------------------------process
exe.time
wait time
turn time
-----------------------------------------------------------------------------------------------------------P1
P2
P3
P4

2
3
4
6
0
2
5
9
2
5
9
13
Avg wait time:4
Avg turn time:7.75
PRIORITY SCHEDULING
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],b[20],i,j,t,n;
float p=0,awt=0,att=0,tt=0,wt=0;
clrscr();
printf("enter process:");

scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the exe.time:");
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
printf("enter the priority:");
scanf("%d",&b[i]);
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(b[j]>b[i])
{
t=a[i];
a[i]=a[j];
a[j]=t;
t=b[i];
b[i]=b[j];
b[j]=t;
}

}
printf("\n\t\t\tPRIORITY");
printf("\n-----------------------------------------------------------------\n");
printf("\npro\texe.time\tpriority\twaittime\tturntime");
printf("\n-----------------------------------------------------------------\n");
for(i=1;i<=n;i++)
{
wt=awt+p;
tt=tt+a[i];
p=a[i];
awt=awt+wt;
att=att+tt;
printf("\np%d\t%d\t\t%d\t\t%f\t%f",i,a[i],b[i],wt,tt);
}
printf("\n----------------------------------------------------------------\n") ;
printf("avg wait time:%f\n",awt/n);
printf("avg turn around time:%f\n",att/n);
getch();
}
OUTPUT:
Enter process:4
Enter the exe.time:3
Enter the exe.time:6

Enter the exe.time:4


Enter the exe.time:2
Enter the priority:2
Enter the priority:4
Enter the priority:1
Enter the priority:3
PRIORITY
-----------------------------------------------------------------------------------------------------------process
exe. Time
priority
wait time
turn time
-----------------------------------------------------------------------------------------------------------P1
P2
P3
P4
4
3
2
6
1
2
3

4
0
4
7
13
Avg wait time:6
Avg turn around time:8.75
ROUND-ROBIN SCHEDULING
#include<iostream.h>
#include<conio.h>
void main()
{
int b=1,n,e[50],q,i,j,rt[50],ct[50]={0},tot=0,wt=0,await[50]={0},ee[20];
float avgwait=0.0,avgturn,turn,sum=0,taround[20],total=0.0;
clrscr();
cout<<"\n enter the no.of process:";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"\n enter the exe.time:";
cin>>e[i];
ee[i]=e[i];
rt[i]=e[i];

tot+=e[i];
sum=sum+e[i];
}
cout<<"\n enter the time slice:";
cin>>q;
while(tot>wt)
{
cout<<b;
for(i=1;i<=n;i++)
{
if((rt[i]>q)&&(ct[i]<e[i]))
{
rt[i]=rt[i]-q;
ct[i]=ct[i]+q;
cout<<"\n remaining time of process"<<i<<"="<<rt[i];
cout<<"\n completion time of process"<<i<<"="<<ct[i];
wt+=q;
}
else if(e[i])
{
cout<<"\n process %dcompleted"<<i;
await[i]=wt-ct[i];
wt+=rt[i];

e[i]=0;
}
}
b++;
}
clrscr();
cout<<"\n\t\t\tROUND ROBIN\n";
cout<<"\n............................................................\n";
cout<<"\nprocess\texe.time\twait time\tturn time";
cout<<"\n.............................................................\n";
for(i=1;i<=n;i++)
{
total=total+await[i];
turn=sum+total;
}
for( i=1;i<=n;i++)
{
taround[i]=await[i]+ee[i];
cout<<"\np"<<i<<"\t"<<ee[i]<<"\t\t"<<await[i]<<"\t\t"<<taround[i];
}
cout<<"\n................................................................\n";
avgwait=total/n;
cout<<"\n average wait time:"<<avgwait;

avgturn=turn/n;
cout<<"\n average turn around time is:"<<avgturn;
getch();
}
OUTPUT:
Enter the no. of process:4
Enter the exe.time:3
Enter the exe.time:6
Enter the exe.time:4
Enter the exe.time:2
Enter the time slice:2
ROUND ROBIN
-----------------------------------------------------------------------------------------------------------process
exe.time
wait time
turn time
-----------------------------------------------------------------------------------------------------------P1
P2
P3
P4
-----------------------------------------------------------------------------------------------------------Average wait time:7.5
Average turn around time:11.25

3
6
4
2
6
9
9
6
BANKERS ALGORITHM
#include<stdio.h>
#include<conio.h>
int n,r,need[10][10],max[10][10],alloc[10][10],a[10];
int i,j,k,t,temp[10],p=0,in[10]={0},x=0;
void needed();
void allocation();
void nuavail();
void main()
{
clrscr();
printf("\nEnter the no. of process:");
scanf("%d",&n);
printf("\nEnter the no. of resources:");
scanf("%d",&r);

for(i=1;i<=n;i++)
{
printf("\nEnter the current allocation to process %d",i);
for(j=1;j<=r;j++)
{
scanf("%d",&alloc[i][j]);
}
}
for(i=1;i<=n;i++)
{
printf("\nEnter the Max.allocation for process %d",i);
for(j=1;j<=r;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("\nEnter the available resources\n");
for(i=1;i<=r;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{

for(j=1;j<=r;j++)
{
need[i][j]=max[i][j]-alloc[i][j];
}
}
needed();
allocation();
while(p<n)
{
for(i=1;i<=n;i++)
{
t=0;
if(in[i]==0)
{
for(j=1;j<=r;j++)
{
if(a[j]>=need[i][j])
t++;
}
}
if(t==r)
{
if(in[i]!=1)

{
x++;
temp[x]=i;
in[i]=1;
printf("\nNeed of p%d is satisfied",i);
p++;
for(k=1;k<=n;k++)
{
a[k]=a[k]+alloc[i][k];
alloc[i][k]=0;
}
nuavail();
}
}
}
if(p==0)
{
printf("\nThere is deadlock");
break;
}
}
if(p==n)
{

printf("\nSafe sequence is");


for(i=1;i<=n;i++)
{
printf("\tp%d",temp[i]);
}
}
getch();
}
void nuavail()
{
int l,m;
printf("\n");
printf("\nNew available resources");
for(l=1;l<=r;l++)
{
printf("\t%d",a[l]);
}
allocation();
}
void needed()
{
int l,m;
printf("\nNeed");

for(l=1;l<=r;l++)
{
printf("\t r%d",l);
}
for(l=1;l<=n;l++)
{
printf("\np%d",l);
for(m=1;m<=r;m++)
{
printf("\t%d",need[l][m]);
}
}
}
void
allocation()
{
int l,m;
printf("\nAllocation");
printf("\n");
for(l=1;l<=r;l++)
{
printf("\t r%d",l);
}

for(l=1;l<=n;l++)
{
printf("\n p%d \t",l);
for(m=1;m<=r;m++)
{
printf("\t %d",alloc[l][m]);
}
}
getch();
}
OUTPUT:
BANKERS ALGORITHM
Enter the number of process:3
Enter the number of Resources:1
Enter the current allocation to process 1:
Enter the current allocation to process 2:
Enter the current allocation to process 3:
Enter the Maximum allocation for process 1:10
Enter the Maximum allocation for process 2:4
Enter the Maximum allocation for process 3:
Enter the available Resources:
Need
p1

p2
p3
Allocation
5
2
2
3
3
r1
5
2
1
p1
p2
p3
Need of p2 satisfied
New available Resources:
Allocation
r1
5
2
2
5

r1
p1
p2
p3
Need of p3 is satisfied
New Available Resources:
Allocation
5
0
2
7
p1
p2
p3
Need of p1 is satisfied
New Available Resources:
Allocation
r1
5
0
0
12
p1

p2
p3
Safe sequence is p2 p3 p1
r1
0
0
0
PRODUCER AND CONSUMER PROBLEM
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int n=3,m,item,buf[3],i;
void wait()
{
m=1;
printf("\n Enter the critical section");
}
void signal()
{
m=0;
printf("\n Quitting the critical section");
}
void producer()

{
wait();
printf("Enter the data to produce:");
scanf("%d",&item);
buf[i]=item;
i++;
signal();
}
void consumer()
{
wait();
printf("\n The data to be consumed:%d",buf[i-1]);
i--;
signal();
}
void main()
{
int ch;
clrscr();
start:
printf("\n Menu:n\t1=producer\n\t2=consumer\n Enter your choice:");
scanf("%d",&ch);
if(ch==1)

{
if(1==n)
{
printf("\n Buffer full");
}
else
{
producer();
goto start;
}}
else if(ch==2)
{
if(i==0)
{
printf("\n no Item to consume");
}
else
{
consumer();
goto start;
}
}
else

{
exit(0);
}
getch();
}
OUTPUT:
MENU:
1.Producer
2.Consumer
Enter your choice:
Entering the critical section.
Enter the data to produce:
Quitting the critical section.
MENU:
1.Producer
2.Consumer
Enter your choice:
Entering the Critical section .
Enter the data to produce:
Quitting the critical section
MENU:
1.Producer
2.Consumer

Enter your choice:


Entering the critical section.
The data has been Consumed :
Quitting the critical section
MENU:
1.Producer
1
6
1
5
2
5
2.Consumer
Enter your choice:
Entering the critical section..
The data has been Consumed:6
Quitting the critical section.
MENU:
1.Producer
2.Consumer
Enter your choice:
No item to Consume..
2

2
DINING PHILOSOPHER ALGORITHM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5]={0,0,0,0,0},b[5]={0,0,0,0,0},g,x,y,z=0,i=0,j=0,k,n;
clrscr();
printf("\nEnter the no. of philosopher");
scanf("\n%d",&n);
while(z<n)
{
if((a[(i%5)+1]==0)&&(b[(j%5)+1])&&(a[((i+1)%5)+1]==0))
{
a[(i%5)+1]=1;
b[(j%5)+1]=1;
a[((i+1)%5)+1]=1;
printf("\nPhilospher %d is eating\tChopstick free:%d,%d\nplate:%d\n",++z,(i%5)
+1,((i+1)%5)+1,(j%5)+1);
a[(x%5)+1]=0;
b[(y%5)+1]=0;
a[((x+1)%5)+1]=0;
x=i;
y=j;

}
i=i+1;
j=j+1;
}
getch();
}
OUTPUT:
Enter the Number of the philosopher:10
Philosopher 1 is eating
Chop Stick free:
Plate: 1
Philosopher 2 is eating
Chop Stick free: 3& 4
Plate: 3
Philosopher 3 is eating
Chop Stick free: 5&1
Plate: 5
Philosopher 4 is eating
Chop Stick free: 2&3
Plate: 2
Philosopher 5 is eating
Chop Stick free: 4&5
Plate: 4

Philosopher 6 is eating
Chop Stick free: 1&2
Plate: 1
Philosopher 7 is eating
Chop Stick free: 3&4
Plate: 3
1&2
Philosopher 8 is eating
Chop Stick free: 5&1
Plate: 5
Philosopher 9 is eating
Chop Stick free: 2&3
Plate: 2
Philosopher 10 is eating
Chop Stick free: 4&5
Plate: 4
STORAGE REPLACEMENT
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void first(int);
void best(int);
void worst(int);

struct slot
{
int size;
int job;
int inuse;
}a[25];
void main()
{
int item,x,n,i,ch;
char ans;
clrscr();
printf("\nStorage Placement");
printf("\nEnter the limit:");
scanf("%d",&x);
printf("\nEnter the size:");
for(i=0;i<x;i++)
{
scanf("%d",&a[i].size);
}
for(i=0;i<x;i++)
{
a[i].inuse=0;
}

printf("\nSlot \t size \t Inuse");


for(i=0;i<x;i++)
{
printf("\n %d \t %d \t %d",i+1,a[i].size,a[i].inuse);
}
do
{
printf("\nOptions\n");
printf("\n~~~~~~~");
printf("\n1.First Fit\n2.Best Fit\n3.Worst Fit\n4.Exit");
printf("\nEnter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
first(x);
break;
case 2:
best(x);
break;
case 3:
worst(x);
break;

case 4:
exit(0);
break;
}
printf("\nDo you want to continue:%c",ans);
ans=getche();
}
while(ans=='y'||ans=='Y');
getch();
}
void first(int x)
{
int item,i,c,p,k;
printf("\nEnter the job:");
scanf("%d",&item);
for(i=0;i<x;i++)
{
if((a[i].inuse!=1)&&(a[i].size>=item)&&(k!=1))
{
a[i].job=item;
a[i].inuse=1;
k=1;
}

}
if(k==1)
{
printf("\nThe given job %d is allocated by first fit",item);
}
else
{
printf("\nThere is no slot to allocate the job");
}
printf("\nSLOT \t SIZE \t INUSE");
for(i=0;i<x;i++)
{
printf("\n %d %d\t %d",i+1,a[i].size,a[i].inuse);
}
}
void best(int x)
{
int item,c,i,p,d=99;
printf("\nEnter the job:");
scanf("%d",&item);
for(i=0;i<x;i++)
{
if(a[i].inuse!=1)

{
if((a[i].size-item>0)&&(a[i].size-item<d))
{
d=a[i].size-item;
c=i;
p=1;
}
}
}
a[c].job=item;
a[c].inuse=1;
if(p==1)
{
printf("\nThe given job %d is allocated by best fit",item);
}
else
{
printf("\nThere is no slot to allocate the job");
}
printf("\nSLOT \t SIZE \t INUSE");
for(i=0;i<x;i++)
{
printf("\n %d \t %d \t %d",i+1,a[i].size,a[i].inuse);

}
}
void worst(int x)
{
int item,c,p,i,d=0;
printf("\nEnter the job:");
scanf("%d",&item);
for(i=0;i<x;i++)
{
if(a[i].inuse!=1)
{
if(a[i].size-item>d)
{
d=a[i].size-item;
c=i;
p=1;
}
}
}
a[c].job=item;
a[c].inuse=1;
if(p==1)
{

printf("\nThe given job %d is allocated by worst fit",item);


}
else
{
printf("There is no slot to allocate the job");
}
printf("\nSLOT \t SIZE \t INUSE");
for(i=0;i<x;i++)
{
printf("\n%d \t %d \t %d",i+1,a[i].size,a[i].inuse);
}
}
OUTPUT:
STORAGE REPLACEMENT
Enter the limit:
Enter the size: 58
SLOT SIZE INUSE
1
58
2
95
75
3

4
44
5
62
OPTIONS:
1.First Fit
2.Best Fit
3.Worst Fit
4.Exit
Enter the choice:
Enter the job: 25
The given job 25 is allocated by First Fit
SLOT SIZE INUSE
1
58
2
95
3
75
4
44
62
5

5
95
75
44
62
0
0
0
0
0
1
1
0
0
0
0
Do you want to continue:
OPTIONS:
1.First Fit
2.Best Fit
3.Worst Fit
4.Exit
Enter the choice:

Enter the job: 74


The given job 74 is allocated by Best Fit.
SLOT SIZE INUSE
1
58
95
2
3
75
4
44
62
5
Do you want to continue:
OPTIONS:
1.First Fit
2.Best Fit
3.Worst Fit
4.Exit
Enter the choice:
Enter the job: 26
The given job 26 is allocated by Worst Fit
Y

2
1
0
1
0
0
Y
3
SLOT SIZE INUSE
1
58
2
95
75
3
4
44
5
62
Do you want to continue:
1
1
1

0
0
Y
OPTIONS:
1.First Fit
2.Best Fit
3.Worst Fit
4.Exit
Enter the choice:
Enter the job: 60
The given job 60 is allocated by First Fit
SLOT SIZE INUSE
1
58
2
95
3
75
4
44
62
5
Do you want to continue:

OPTIONS:
2
1
1
1
0
1
Y
1.First Fit
2.Best Fit
3.Worst Fit
4.Exit
Enter the choice:
Enter the job: 34
The given job 34 is allocated by first fit
SLOT SIZE INUSE
58
1
2
95
3
75
44

4
5
62
Do you want to continue:
OPTIONS:
1.First Fit
2.Best Fit
3.Worst Fit
4.Exit
Enter the choice:
Enter the job: 34
There is no slot to allocate the job.
Do you want to continue:
1
1
1
1
1
1
Y
1
Y

PAGE REPLACEMENT (FIFO)


#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],b[3],n,i,j,m,k,l;
clrscr();
printf("\nEnter the size of the Memory");
scanf("\n%d",&n);
printf("Enter the number of the process");
scanf("\n%d",&m);
printf("Enter the process");
for(i=0;i<m;i++)
scanf("\n%d",&a[i]);
a[m]=99;
for(i=0;i<n;i++)
b[i]=-1;
i=0;
j=0;
printf("\n----------------\n");
while(a[i]!=99)
{
k=0;

for(l=0;l<=n;l++)
{
if(a[i]==b[j])
{
k=1;
break;
}
}
if(k!=1)
{
b[j]=a[i];
j++;
j=j%n;
}
i++;
for(k=0;k<n;k++)
printf("\n%d",b[k]);
printf("\n******************\n");
}
getch();
}
OUTPUT:
PAGE REPLACEMENT(FIFO)

3
Enter Size of Memory:
Enter the Number of Process: 6
Enter the Process:
2
3
4
5
6
----------------------------1
-1
-1
*******************
1
2
-1
*******************
1
2
3
*******************
4

2
1
3
3
*******************
4
5
3
*******************
4
5
6
*******************
PAGE REPLACEMENT (LRU)
#include<stdio.h>
#include<conio.h>
int nf,ne,miss,hit,ref[50],fr[15];
void getdata();
void lru();
int search(int);
int large(int []);
void getdata()
{

int i;
printf("\nEnter the number of frames:");
scanf("\n%d",&nf);
printf("\nEnter the reference string:");
scanf("\n%d",&ne);
for(i=0;i<ne;i++)
scanf("\n%d",&ref[i]);
}
void lru()
{
int i,j,k,l,t,tl=0,tem[25],temp=0;
miss=hit=0;
for(i=0;i<nf;i++)
fr[i]=0;
for(i=0;i<nf;i++)
{
printf("\nNumber to be inserted:%d",ref[i]);
temp=search(ref[i]);
if(temp==0)
{
miss++;
fr[i]=ref[i];
tl++;

}
else
hit++;
for(j=0;j<nf;j++)
printf("\t%d",fr[i]);
}
for(i=nf;i<ne;i++)
{
printf("\nNNumber to be inserted:%d",ref[i]);
temp=search(ref[i]);
if(temp==0)
{
miss++;
for(j=0;j<nf;j++)
{
tem[j]=0;
for(k=i-1;k>=0;k--)
{
if(ref[k]==fr[j])
break;
tem[j]++;
}
}

t=large(tem);
fr[t]=ref[i];
}
else
hit++;
for(j=0;j<nf;j++)
printf("\t%d",fr[j]);
}
printf("\n\nNumber of pages faults=%d\n",miss);
printf("\number of hits=%d",hit);
}
int large(int tem[])
{
int i,nl,n=0;
nl=tem[0];
for(i=0;i<(nf-1);i++)
{
if(tem[i+1]>nl)
{
nl=tem[i+1];
n=i+1;
}
}

if(nl==tem[0]);
n=0;
return(n);
}
int search(int item)
{
int i;
for(i=0;i<(nf-1);i++)
{
if(fr[i]==item)
return(1);
}
return 0;
}
void main()
{
int i;
char c;
clrscr();
printf("\nPage replacement");
getdata();
lru();
getch();

}
OUTPUT:
PAGE REPLACEMENT (LRU)
Enter the number of frames: 3
Enter the number of elements in the reference strings:
Enter the reference strings:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number to be inserted:
Number of page faults=
Number of hits=2
9
762120304
700
7
760
6

762
2
162
1
2
162
102
0
302
3
0
302
4
304
7

You might also like