-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsjf.cpp
52 lines (52 loc) · 1.06 KB
/
sjf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<conio.h>
#define max 30
int main()
{
int i,j,n,t,p[max],bt[max],wt[max],tat[max];
float awt=0,atat=0;
printf("Enter the name of the process");
scanf("%d",&n);
printf("Enter the process number");
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
printf("Enter the burst time of process");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
//applying bubble sort technique to sort according to their burst time for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(bt[j]>bt[j+1])
{
t=bt[j];
bt[j]=bt[j+1];
bt[j+1]=t;
t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
printf("\nprocess \t burst time \t waiting time \t turn around time\n"); for(i=0;i<n;i++)
{
wt[i]=0;
tat[i]=0;
for(j=0;j<i;j++)
{
wt[i]=wt[i]+bt[j];
}
tat[i]=wt[i]+bt[i];
awt=awt+wt[i];
atat=atat+tat[i];
printf("%d\t %d\t\t %d\t\t %d\n",p[i],bt[i],wt[i],tat[i]); }
awt=awt/n;
atat=atat/n;
printf("Average waiting time =%f\n",awt);
printf("Average turn around time=%f",atat);
getch();
}