#include
#include
#include
#include
void main()
{
int p[10],ptemp;
int b[10];
int w[10];
int t[10];
int n,i,j,tw,ttat,btemp;
float avgw,avgtat;
clrscr();
printf("\n\tProgram for SJF Scheduling");
printf("\n\nEnter the Total Number Of Processes:");
scanf("%d",&n);
for(i=0;i
{
//printf("Enter the Name Of Process%d:",(i+1));
//scanf("%d",&p[i]);
p[i]=i+1;
printf("\nEnter the burst time for Process%d:",(i+1));
scanf("%d",&b[i]);
}
for(j=0;j
{
for(i=0;i
{
if(b[i]>b[i+1])
{
btemp=b[i];
b[i]=b[i+1];
b[i+1]=btemp;
ptemp=p[i];
p[i]=p[i+1];
p[i+1]=ptemp;
}
}
}
w[0]=0;
tw=w[0];
t[0]=b[0];
ttat=t[0];
for(i=0;i
{
w[i+1]=w[i]+b[i];
tw=tw+w[i+1];
t[i+1]=t[i]+b[i+1];
ttat=ttat+t[i+1];
}
avgw=tw/n;
avgtat=ttat/n;
printf("\n\n\t|");
for(i=0;i
{
printf("\tP%d\t|",p[i]);
}
printf("\n\t%d",w[0]);
for(i=0;i
{
printf("\t \t%d",t[i]);
}
printf("\n\nProcess id \t Burst Time \t Wait Time \t T-Around Time \n");
for(i=0;i
{
printf("P%d\t\t %d\t\t %d\t\t %d\n",p[i],b[i],w[i],t[i]);
}
printf("\n\nAverage wait Time:%f\n",avgw);
printf("Average Turn Arount:%f",avgtat);
getch();
}
/* OUTPUT
Enter the Total Number Of Processes:4
Enter the burst time for Process1:8
Enter the burst time for Process2:2
Enter the burst time for Process3:5
Enter the burst time for Process4:1
| P4 | P2 | P3 | P1 |
0 1 3 8 16
Process id Burst Time Wait Time T-Around Time
P4 1 0 1
P2 2 1 3
P3 5 3 8
P1 8 8 16
Average wait Time:3.000000
Average Turn Arount:7.000000
*/
0 comments:
Post a Comment