FCFS SJF RR
FCFS SJF RR
FCFS SJF RR
mokal
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
int n,bt[20],wt[20],tat[20],ts=0,avwt=0,avtat=0,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
printf("P[%d]:",i+1);
scanf("%d",&bt[i]);
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
avwt=avwt/n;
avtat/=i;
for (i=0;i<n;i++)
printf("| p %d ",i);
printf("| \n");
for(i=0;i<=n;i++)
printf("%d ",ts);
ts=ts +bt[i];
return 0;
}
OUTPUT:
//Name: Vaishnavi p. mokal
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,ts=0,pos,temp;
float avg_wt,avg_tat;
scanf("%d",&n);
for(i=0;i<n;i++)
printf("p%d:",i+1);
scanf("%d",&bt[i]);
for(i=0;i<n;i++)
pos=i;
for(j=i+1;j<n;j++)
if(bt[j]<bt[pos])
pos=j;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
total=0;
for(i=0;i<n;i++)
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
for (i=0;i<n;i++)
printf("| p %d ",p[i]);
printf("| \n");
for(i=0;i<=n;i++)
printf("%d ",ts);
ts=ts +bt[i];
return 0;
}
OUTPUT:
//Name:Vaishnavi p. mokal
#include<stdio.h>
int at[100],bt[100],rt[100],temp[100];
float wait_time=0,turn_time=0;
void main()
int c,j,n,time,r,flag=0,time_q,ltt,i,wt=0;
scanf("%d",&n);
r=n;
for(c=0;c<n;c++)
scanf("%d",&at[c]);
scanf("%d",&bt[c]);
rt[c]=bt[c];
temp[c]=bt[c];
printf("\n");
scanf("%d",&time_q);
printf("\n\n\tprocess\tAT\tBT\tTAT\tWT \n\n");
for(time=0,c=0;r!=0;)
time=time+rt[c];
rt[c]=0;
flag=1;
}
else if (rt[c]>0)
rt[c]=rt[c]-time_q;
time=time+time_q;
wt=0;
wt=time-at[c]-bt[c];
r--;
printf("\tP%d\t%d\t%d\t%d\t%d\n",c+1,at[c],bt[c],time-at[c],wt);
ltt=time-at[c];
wait_time=wait_time+time-at[c]-bt[c];
turn_time=turn_time+time-at[c];
flag=0;
if(c==n-1)
c=0;
else if(at[c+1]<=time)
c++;
else
c=0;
j=0;
printf("\n\n\n");
printf("\n\n\n");
printf("\t");
for(i=at[0];i<time;)
if(bt[j]>=time_q)
{
printf("P%d\t",j+1);
i+=time_q;
bt[j]=bt[j]-time_q;
else if(bt[j]>0)
printf("p%d\t",j+1);
i+=bt[j];
bt[j]=0;
j++;
if(j>=n)
j=0;
printf("\n");
j=0;
printf("\t");
for(i=at[0];i<time;)
if(temp[j]>=time_q)
printf("%d\t",i+time_q);
i+=time_q;
temp[j]=temp[j]-time_q;
else if(temp[j]>0)
printf("%d\t",i+temp[j]);
i+=temp[j];
temp[j]=0;
j++;
if(j>=n)
j=0;
printf("\n\n\n");
printf("\nAverage_waiting_time=%f\n",wait_time/n);
printf("Average_turn_around_time=%f\n",turn_time/n);
printf("\n\n");
OUTPUT: