forked from iedcbootcampcec/letshack-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_6125194092235195296.c
119 lines (83 loc) · 1.8 KB
/
5_6125194092235195296.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//2. PROGRAM OF STF
#include <stdio.h>
int main()
{
int at [100], bt[100], proces [100], ct [100], tat [100], wt [100];
int n, i, j, temp, current_time=0, start_time, completed=0 ,count;
float avg_tat=0.0, avg_wt=0.0;
printf ("Enter the number of processes:");
scanf ("%d", &n);
for(i=0; i<n; i++)
{
printf ("\n Enter the arival time of process %d :", i);
scanf ("%d", & at [i]);
printf ("\n Enter the burst time of process %d :", i);
scanf ("%d", & bt[i]);
proces [i]= i;
printf("\n");
}
for(i=0; i<n-1; i++)
{
for (j=i+1; j<n; j++)
{
if (at[i]> at [j])
{
temp=at[i];
at[i] = at[j];
at[j] = temp;
temp=bt[i];
bt[i]=bt[j];
bt[j]=temp;
temp = proces [i];
proces [i] = proces [j];
proces[j]=temp;
}
}
}
//Scanned with CamScanne
printf ("\n\n Process\t Arival time\t Burst Time\t Completion time\t Turn Around time\t waiting Time\n\n");
while (completed <n)
{
count = 0;
for (i=completed; i<n; i++)
{
if (at[i]<= current_time)
count++;
else{
break;
}
}
if (count >1)
for (i=completed; i< (completed + count-1); i++)
{
for(j=i+1; j<completed + count; j++)
{
if (bt[i]>bt[j])
{
temp=at[i];
at[i] = at[j];
at[j] = temp;
temp=bt[i];
bt[i]=bt[j];
bt[j]=temp;
temp = proces [i];
proces [i] = proces [j];
proces[j]=temp;
}}}
start_time = current_time;
ct[completed]=start_time + bt [completed];
tat [completed]= ct [completed]-at [completed];
wt [completed]=tat [completed]-bt[completed];
current_time = ct [completed];
printf ("P%d\t\t%d\t\t%d\t\t%d\t\t %d\t\t %d", proces [completed], at[completed], bt[completed],ct[completed], tat [completed], wt [completed]);
printf("\n");
avg_tat+=tat [completed];
avg_wt+= wt[completed];
completed++;
}
avg_tat=avg_tat/n;
avg_wt = avg_wt/n;
printf ("Average Turn around time=%.f\n", avg_tat);
printf ("Average waiting time = %f \n", avg_wt);
return 0;
}