Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions algorithms/roundrobin.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ int main()
int i, limit, total = 0, x, counter = 0, time_quantum;
int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10];
float average_wait_time, average_turnaround_time;
printf("nEnter Total Number of Processes:t");
printf("\nEnter Total Number of Processes: ");
scanf("%d", &limit);
x = limit;
for(i = 0; i < limit; i++)
{
printf("nEnter Details of Process[%d]n", i + 1);
printf("\nEnter Details of Process[%d]\n", i + 1);

printf("Arrival Time:t");
printf("Arrival Time: ");

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

printf("Burst Time:t");
printf("Burst Time: ");

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

temp[i] = burst_time[i];
}

printf("nEnter Time Quantum:t");
printf("\nEnter Time Quantum: ");
scanf("%d", &time_quantum);
printf("nProcess IDttBurst Timet Turnaround Timet Waiting Timen");
printf("\nProcess ID\t\tBurst Time\t Turnaround Time\t Waiting Time\n");
for(total = 0, i = 0; x != 0;)
{
{
if(temp[i] <= time_quantum && temp[i] > 0)
{
total = total + temp[i];
Expand All @@ -42,7 +42,11 @@ int main()
if(temp[i] == 0 && counter == 1)
{
x--;
printf("nProcess[%d]tt%dtt %dttt %d", i + 1, burst_time[i], total - arrival_time[i], total - arrival_time[i] - burst_time[i]);
printf("\nProcess [%d]\t\t%d\t\t %d\t\t\t %d", i + 1,
burst_time[i],
total - arrival_time[i],
total - arrival_time[i] - burst_time[i]);

wait_time = wait_time + total - arrival_time[i] - burst_time[i];
turnaround_time = turnaround_time + total - arrival_time[i];
counter = 0;
Expand All @@ -63,7 +67,8 @@ int main()

average_wait_time = wait_time * 1.0 / limit;
average_turnaround_time = turnaround_time * 1.0 / limit;
printf("nnAverage Waiting Time:t%f", average_wait_time);
printf("nAvg Turnaround Time:t%fn", average_turnaround_time);
printf("\n\nAverage Waiting Time: %.2f", average_wait_time);
printf("\nAvg Turnaround Time: %.2f\n", average_turnaround_time);
getchar();
return 0;
}