Program of first come first serve(FCFS) in Operating Sysytem
#include<stdio.h>
#include<conio.h>
void main()
{
int a,n,i,j,pa[10],pb[10],pt[10], pc[10],pw[10],ptat[10],pa2[10] ;
printf("Enter the no. of process");
scanf("%d",&n);
for(a=0;a<n;a++)
{
printf("Enter the arrival time and the cpu brust time of process %d\n",a+1);
scanf("%d%d",&pa[a],&pb[a]);
pc[a]=pb[a];
pa2[a]=pa[a];
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(pa[i]>pa[j])
{
a=pa[i];
pa[i]=pa[j];
pa[j]=a;
a=pb[i];
pb[i]=pb[j];
pb[j]=a;
}
}
}
for(a=0;a<n;a++)
{
printf("\n%d\t%d",pa[a],pb[a]) ;
}
printf("\n");
pt[0]=0;
for(a=1;a<n;a++)
{
pt[a]=pt[a-1]+pb[a-1];
}
for(a=0;a<n;a++)
{
pw[a]=pt[a]-pa[a];
ptat[a]=pw[a]+pb[a];
//printf("\nWaiting Time %d\t %d",a+1,pw[a]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(pb[j]==pc[i] && pa[j]==pa2[i])
printf("\nTAT%d \t %d",i+1,ptat[j]);
}
}
printf("\n");
i=0;
for(a=0;a<n;a++)
{
i=i+ptat[a];
}
printf("\nTotal TAT = %d\nAverage TAT = %d",i,i/n);
getch();
}
#include<conio.h>
void main()
{
int a,n,i,j,pa[10],pb[10],pt[10],
printf("Enter the no. of process");
scanf("%d",&n);
for(a=0;a<n;a++)
{
printf("Enter the arrival time and the cpu brust time of process %d\n",a+1);
scanf("%d%d",&pa[a],&pb[a]);
pc[a]=pb[a];
pa2[a]=pa[a];
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(pa[i]>pa[j])
{
a=pa[i];
pa[i]=pa[j];
pa[j]=a;
a=pb[i];
pb[i]=pb[j];
pb[j]=a;
}
}
}
for(a=0;a<n;a++)
{
printf("\n%d\t%d",pa[a],pb[a])
}
printf("\n");
pt[0]=0;
for(a=1;a<n;a++)
{
pt[a]=pt[a-1]+pb[a-1];
}
for(a=0;a<n;a++)
{
pw[a]=pt[a]-pa[a];
ptat[a]=pw[a]+pb[a];
//printf("\nWaiting Time %d\t %d",a+1,pw[a]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(pb[j]==pc[i] && pa[j]==pa2[i])
printf("\nTAT%d \t %d",i+1,ptat[j]);
}
}
printf("\n");
i=0;
for(a=0;a<n;a++)
{
i=i+ptat[a];
}
printf("\nTotal TAT = %d\nAverage TAT = %d",i,i/n);
getch();
}
Share This:
-
PrevoiusYou are viewing Most Recent Post
-
Next
No Comment to " Program of first come first serve(FCFS) in Operating Sysytem "