#include<stdio.h>
#include<string.h>
float avgwt, avgtt;
char pname[10][10], c[10][10];
int at[10], wt[10], tt[10], bt[10], n, sum = 0, ttime, j, ss = 0, count = 0, indexar[10], ix = 0, k, ix1, ix2, choice;
void table()
{
int i;
printf("\nPROCESS\t ARRIVAL TIME \t BURST TIME \t WAITING TIME \t TURN AROUND TIME\t");
for (i = 0; i < n; i++) {
printf("\n%s\t\t%d\t\t%d\t\t%d\t\t%d\t", pname[i],at[i],bt[i],wt[i],tt[i]);
}
}
void gantt_chart() {
int i;
printf("\nGRANTT CHART\n");
for (i = 0; i < n; i++) {
printf("|\t%s\t", pname[i]);
}
printf("|\n");
for (i = 0; i < n; i++) {
printf("%d\t\t", wt[i]);
}
printf("%d\n", ss);
}
int main() {
printf("Enter the number of processes:");
scanf("%d", &n);
printf("Enter the NAME, ARRIVAL TIME, BURST TIME of the process\n");
for (int i = 0; i < n; i++) {
printf("\nPROCESS NAME: ");
scanf("%s", pname[i]);
printf("ARRIVAL TIME: ");
scanf("%d", &at;[i]);
printf("BURST TIME: ");
scanf("%d", &bt;[i]);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (at[i] > at[j]) {
int temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
temp = at[i];
at[i] = at[j];
at[j] = temp;
char tempStr[10];
strcpy(tempStr, pname[i]);
strcpy(pname[i], pname[j]);
strcpy(pname[j], tempStr);
}
}
}
wt[0] = at[0];
sum = 0;
ss = bt[0];
tt[0] = wt[0] + bt[0];
for (int i = 1; i < n; i++) {
wt[i] = wt[i - 1] + bt[i - 1];
sum = sum + (wt[i] - at[i]);
tt[i] = wt[i] + bt[i];
ss = ss + bt[i];
}
avgwt = (float)sum / n;
avgtt = (float)ss / n;
printf("\nAverage waiting time=%f", avgwt);
printf("\nAverage turn-around time=%f", avgtt);
printf("\nGANTT CHART FCFS SCHEDULING\n");
table();
gantt_chart();
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"}