FCFS scheduling ( Improve this code )
#include <stdio.h> int main() { int n; printf("Enter number of jobs to schedule - \n"); scanf("%d",&n); int burst[n],arrival[n],index[n]; int i,tot=0; printf("Enter the burst time of the jobs - \n"); for(i=0;i<n;i++) { index[i]=i+1; scanf("%d",&burst[i]); } printf("Enter the arrival time of the jobs - \n"); for(i=0;i<n;i++) { scanf("%d",&arrival[i]); } int j; for(i=0;i<n;i++) { int min=arrival[i]; int pos=i; for(j=i+1;j<n;j++) { if(arrival[j]<min) { min=arrival[j]; pos=j; } } int temp=arrival[i]; arrival[i]=min; arrival[pos]=temp; temp=burst[i]; burst[i]=burst[pos]; burst[pos]=temp; temp=index[i]; index[i]=index[pos]; index[pos]=temp; } int time=0; double avgtat=0; for(i=0;i<n;i++) { while(time<arrival[i]) time++; time+=burst[i]; avgtat+=(time-arrival[i]); } avgtat/=n; printf("The jobs will be processed in this order - "); for(i=0;i<n;i++) printf("%d\t",index[i]); printf("\nThe total time taken to complete all the jobs will be - %d",time); printf("\nAverage Turnaround Time is - %lf",avgtat); return 0; }