#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,ct[10];
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");
printf("0\t\t");
for (i = 0; i < n; i++) {
printf("%d\t\t", ct[i]);
}
}
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-1; i++) {
for (int j = 0; j < n-1-i; j++) {
if (at[j] > at[j+1]) {
int temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
temp = at[j];
at[j] = at[j+1];
at[j+1] = temp;
char tempStr[10];
strcpy(tempStr, pname[j]);
strcpy(pname[j], pname[j+1]);
strcpy(pname[j+1], tempStr);
}
}
}
wt[0] = 0;
ct[0]=bt[0];
sum = 0;
tt[0] = wt[0] + bt[0];
ss=tt[0];
for (int i = 1; i < n; i++) {
ct[i]=ct[i-1]+bt[i];
tt[i] =ct[i]-at[i];
wt[i] = tt[i]-bt[i];
sum = sum + wt[i];
ss = ss + tt[i];
//printf("%d-ss",ss);
}
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"}