#include #include 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 gantt_chart() { int i; printf("\nGANTT 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); } } } printf("\nEnter your choice:\n"); printf("1. FCFS\n2. Non-Preemptive SJF\n3. Preemptive SJF\n4. Round Robin\n5. Non-Preemptive Priority\n"); scanf("%d", &choice;); switch (choice) { case 1: 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"); gantt_chart(); break; case 2: // Non-Preemptive SJF break; case 3: // Preemptive SJF break; case 4: // Round Robin break; case 5: // Non-Preemptive Priority for (int i = 0; i < n; i++) { count = 0; ix = 0; for (int j = i + 1; j < n; j++) { if (at[j] < (bt[i] + at[i])) { count++; indexar[ix] = j; ix++; } } if (count > 1) { for (k = 1; k < count; k++) { ix1 = indexar[k - 1]; ix2 = indexar[k]; if (bt[ix1] > bt[ix2]) { int temp = bt[ix1]; bt[ix1] = bt[ix2]; bt[ix2] = temp; temp = at[ix1]; at[ix1] = at[ix2]; at[ix2] = temp; char tempStr[10]; strcpy(tempStr, pname[ix1]); strcpy(pname[ix1], pname[ix2]); strcpy(pname[ix2], tempStr); } } } } break; default: printf("Invalid choice!\n"); } return 0; }