#include<stdio.h>

int main()

{

int i,n,count=0,time_quantum,t,at[10],bt[10],rem_bt[10],wt[10],tat[10],flag=0,t=0;

floattotal_wt=0 , total_tat=0

printf("Enter Total Process:\t ");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("Enter Burst Time for Process %d :",i+1);

scanf("%d",&bt[i]);

}

printf("Enter Time Quantum:\t");

scanf("%d",&time_quantum);

for (i = 0 ; i < n ; i++) 

        rem_bt[i] =  bt[i]; 

// Keep traversing processes in round robin manner  until all of them are not done. 

while (1) 

{ 

flag=1; 

// Traverse all processes one by one repeatedly 

for (i = 0 ; i < n; i++) 

{ 

// If burst time of a process is greater than 0 then only need to process further 

if (rem_bt[i] > 0) 

{ 

flag=0; // There is a pending process 

		if (rem_bt[i] > time_quantum) 

		{ 

	// Increase the value of t i.e. shows how much time a process has been processed 

	t += time_quantum; 

		// Decrease the burst_time of current process by quantum 

		rem_bt[i] -= time_quantum;

		} 

// If burst time is smaller than or equal to quantum. Last cycle for this process 

else

{ 

// Increase the value of t i.e. shows how much time a process has been processed 

		t = t + rem_bt[i]; 

		 // Waiting time is current time minus time used by this process 

		wt[i] = t - bt[i]; 

		// As the process gets fully executed make its remaining burst time = 0

		 rem_bt[i] = 0;

}

}

}

if (flag==1)

break;

} 

for (i = 0; i < n ; i++)

	tat[i] = bt[i] + wt[i];

printf("\n Process BT\t WT\t TAT \n");

for(i=0;i<n;i++)

printf("\n %d \t %d \t %d \t %d \t",i+1,bt[i],wt[i],tat[i]);

for (i = 0; i < n ; i++)

{

total_wt= total_wt+wt[i];

total_tat= total_tat+tat[i];

}

printf("\nAverage waiting time = %f", total_wt/n);

printf ("\nAverage turn around time = %f",total_tat/n);

}