You are on page 1of 2

/*CODE SUBMITTED BY:-KAPIL AGRAWAL(NIT RAIPUR) */ //****************FCFS*************************** #include<stdio.h> #include<conio.

h> int main() { int i,timer=0,n; float avg_tat,avg_wt; int total_tat=0,total_wt=0; struct process { int at;//arrival time int bt;//burst time int pid;//process id int wt;//waiting time int tat;//turn around time }p[10],temp;/*NOTE:-This program is limited upto 10 processes only...althoug h this limit can be varied by changing subscript value in p[];*/ printf("enter total no. of processes");/* n has to be less than 10 */ scanf("%d",&n); printf("enter the process id,arrival time,burst time\n"); for(i=0;i<n;i++) { scanf("%d %d %d",&p[i].pid,&p[i].at,&p[i].bt); } for(i=0;i<n;i++) { if(p[i].at>p[i+1].at) { temp=p[i]; /* swapping of processes on basis of their arrival time */ p[i]=p[i+1]; p[i+1]=temp; } } /* calculating the waiting time followed by turn around time of each process */ for(i=0;i<n;i++) { p[i].wt=timer-p[i].at;//waiting time for each process if(p[i].wt<0) { p[i].wt=0; } total_wt=total_wt+p[i].wt; timer=timer+p[i].bt; p[i].tat=timer-p[i].at;//turn around time for each process total_tat=total_tat+p[i].tat;

} avg_tat=(total_tat/n);//avg_tat calculates avg turn around time of all the proce sses avg_wt=(total_wt/n);/*calculating the waiting time for each process */ printf("PID\tTAT\tWT\n"); for(i=0;i<n;i++) { printf("%d\t%d\t%d\n",p[i].pid,p[i].tat,p[i].wt); } printf("Hence the avg turn around time=%f\n",avg_tat); printf("Hence the waiting time=%f\n",avg_wt); //printf("GANTT-CHART:-");

getch(); return 0; }//end of main()

You might also like