//FCFS #include<stdio.h> int main(void) { int n,at[10],bt[10],ct[10],tat[10],wt[10],sum,i,j,k; float totaltat=0,totalwt=0; printf("Enter No of processors:"); scanf(" %d",&n); for(i=0;i<n;i++) { printf("Enter the arrival time of processor %d:",i+1); scanf(" %d",&at[i]); } for(i=0;i<n;i++) { printf("Enter the burst time of processor %d:",i+1); scanf(" %d",&bt[i]); } //Calculation of completion times for each processor sum=at[0]; for(j=0;j<n;j++) { sum=sum+bt[j]; ct[j]=sum; } //Calculation of turn around time for(k=0;k<n;k++) { tat[k]=ct[k]-at[k]; totaltat=totaltat+tat[k]; } //Calculation of waiting time for(i=0;i<n;i++) { wt[i]=tat[i]-bt[i]; totalwt=totalwt+wt[i]; } printf("Process\tAT\tBT\tCT\tTAT\tWt\n"); for(i=0;i<n;i++) { printf("\nP%d\t%d\t%d\t%d\t%d\t%d\t\n",i+1,at[i],bt[i],ct[i],tat[i],wt[i]); } printf("average of turn around time:%0.1f\n",totaltat/n); printf("average of waiting time:%0.1f\n",totalwt/n); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter