/*PROGRAM TO INPLEMENT THE CONCEPTS OF SJF*/
#include<conio.h>
void main()
{
int bt[3],at[3];
int wt[3],ft[3],tat[3];
float awt;
int n,i,sum=0,j,x,z;
char p[3][9],y[9];
clrscr();
printf("\nEnter the process and burst-time:");
for(i=0;i<3;i++)
scanf("%s%d",p[i],&bt[i]);
printf("\nEnter the arrival-time:");
for(i=0;i<3;i++)
scanf("%d",&at[i]);
printf("\nThe actual order:\n");
printf("\nProcess \t Burst-time");
for(i=0;i<3;i++)
printf("\n%s\t%d",p[i],bt[i]);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(bt[i]>bt[j])
{
z=bt[j];
bt[j]=bt[i];
bt[i]=z;
strcpy(y,p[j]);
strcpy(p[j],p[i]);
strcpy(p[i],y);
x=at[j];
at[j]=at[i];
at[i]=x;
}
}
wt[0]=0;
for(i=1;i<3;i++)
wt[i]=wt[i-1]+bt[i-1];
ft[0]=bt[0];
for(i=1;i<3;i++)
ft[i]=ft[i-1]+bt[i];
for(i=0;i<3;i++)
tat[i]=ft[i]-at[i];
for(i=0;i<3;i++)
sum=sum+wt[i];
awt=sum/3.0;
printf("\n\nThe order they are executed:");
printf("\nProcess Burst-time Arrival-time
Waiting-time Finish-time Tuanaround-time\n");
for(i=0;i<3;i++)
printf("\n\n%d%s\t%d\t%d\t\t%d\t%d\t\t%d",
i+1,p[i],bt[i],at[i],wt[i],ft[i],tat[i]);
printf("\n\nAverage waiting time:%f",awt);
}
INPUT:
Enter the process and burst-time:
p1 10
p2 20
p3 30
Enter the arrival-time:
1
2
3
OUTPUT:
The actual order:
Process Burst-time
p1 10
p2 20
p3 30
The order they area executed:
Process Burst-time Arrival-time Waiting-time Finish-time Turnaround-time
p1 30 3 0 30 27
p2 20 2 30 50 48
p3 10 1 50 60 59
Average waiting time:26.666666
If you like this please Link Back to this article...
1 comments:
this is not the real code of sjf. this is fcfs...!
Post a Comment