forked from iedcbootcampcec/letshack-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_6125194092235195293.c
72 lines (55 loc) · 1.09 KB
/
5_6125194092235195293.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
#include <stdio.h>
void main ()
{
int i, n,x, complete=0,count=0, time_quantum;
int at[25], bt[25], temp[25];
float totWT=0, totTAT=0;
printf ("\n Enter the no: of processes:");
scanf ("%d", &n);
x=n;
for (i=0; i<n; i++)
{
printf ("\n Enter arrival time of process %d:", i);
scanf ("%d",&at[i]);
printf ("\n Enter burst time of process %d:",i);
scanf("%d",&bt[i]);
temp[i]=bt[i];
}
printf ("\n Enter the time quantum :");
scanf ("%d", &time_quantum);
printf ("\n\n P.No\t AT\t BT\t CT\t TAT\t WT");
for (complete = 0,i=0;x!=0;)
{
if (temp[i]<= time_quantum & & temp[i]>0)
{
complete+= temp[i];
temp[i]=0;
count = 1;
}
else if(temp[i]>0)
{
temp[i] =temp[i]-time_quantum;
complete +=time_quantum;
}
if (temp[i] == 0 && count == 1)
{
x--;
printf("\nP%d\t%d\t%d\t%d\t%d\t%d",i,at[i],bt[i],complete,complete-at[i],complete - at[i]-bt[i]);
totTAT+= complete - at [i];
totWT+= complete-at[i]-bt[i];
count=0;
}
if (i==n-1)
{
i=0;
}
else if (at [i+1]<= complete)
{i++;
}
else
{
i=0;
}}
printf ("\n Average Turn around Time: %f", (totTAT/n));
printf ("\n Average waiting Time: %f \n", totWT/n);
}