#include <stdio.h>
int main() {
int i, sum = 0, qt, n, temp, count = 0, l = 0, k = 1;
int bt[20], tt[20], wt[20], bt_cp[20], p[20], gt[20], time[20] = {0};
float wt_avg = 0, tt_avg = 0;
printf("\nEnter the number of Processes : ");
scanf("%d", &n);
printf("\nEnter the Burst Time of Each Process:\n");
for (i = 0; i < n; i++) {
p[i] = i + 1;
printf("P%d : ", i + 1);
scanf("%d", &bt;[i]);
bt_cp[i] = bt[i];
}
printf("\nEnter the Time Slice: ");
scanf("%d", &qt;);
while (count != n) {
for (i = 0, count = 0; i < n; i++) {
if (bt_cp[i] == 0) {
count++;
continue;
}
if (bt_cp[i] > qt) {
bt_cp[i] -= qt;
temp = qt;
} else {
temp = bt_cp[i];
bt_cp[i] = 0;
}
sum += temp;
tt[i] = sum;
gt[l++] = p[i];
time[k] = time[k - 1] + temp;
k++;
}
}
for (i = 0; i < n; i++) {
wt[i] = tt[i] - bt[i];
wt_avg += wt[i];
tt_avg += tt[i];
}
wt_avg /= n;
tt_avg /= n;
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (i = 0; i < n; i++)
printf("P%d\t\t%d\t\t%d\t\t%d\n", p[i], bt[i], wt[i], tt[i]);
printf("\nAverage Waiting Time: %.2f ms", wt_avg);
printf("\nAverage Turnaround Time: %.2f ms\n", tt_avg);
printf("\n\n\t\t\t\tGantt Chart\n\n");
printf("----------------------\n");
for (i = 0; i < l; i++)
printf("|\tP%d\t|", gt[i]);
printf("\n--------------------\n");
for (i = 0; i < k; i++)
printf("%d\t \t", time[i]);
printf("\n--------------------\n");
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}