Round Robin Scheduling Program in C++
Round Robin Scheduling Program in C++ Lets seeĀ Round Robin Scheduling program in C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include<stdio.h> int main() { int indicator=0; int total_time_quantum; int count,j,n,time,remain; int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; printf("Please Enter Total Process:\t "); scanf("%d",&n); remain=n; for(count=0;count<n;count++) { printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1); scanf("%d",&at[count]); scanf("%d",&bt[count]); rt[count]=bt[count]; } printf("Enter Time Quantum:\t"); scanf("%d",&total_time_quantum); printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n"); for(time=0,count=0;remain!=0;) { if(rt[count]<=total_time_quantum && rt[count]>0) { time+=rt[count]; rt[count]=0; indicator=1; } else if(rt[count]>0) { rt[count]-=total_time_quantum; time+=total_time_quantum; } if(rt[count]==0 && indicator==1) { remain--; printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]); wait_time+=time-at[count]-bt[count]; turnaround_time+=time-at[count]; indicator=0; } if(count==n-1) count=0; else if(at[count+1]<=time) count++; else count=0; } printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n); printf("Avg Turnaround Time = %f",turnaround_time*1.0/n); return 0; } |