round robin algorithm in c

Solutions on MaxInterview for round robin algorithm in c by the best coders in the world

showing results for - "round robin algorithm in c"
Luis
11 Sep 2020
1#include<stdio.h>
2 
3int main()
4{
5      int i, limit, total = 0, x, counter = 0, time_quantum;
6      int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10];
7      float average_wait_time, average_turnaround_time;
8      printf("nEnter Total Number of Processes:t");
9      scanf("%d", &limit);
10      x = limit;
11      for(i = 0; i < limit; i++)
12      {
13            printf("nEnter Details of Process[%d]n", i + 1);
14 
15            printf("Arrival Time:t");
16 
17            scanf("%d", &arrival_time[i]);
18 
19            printf("Burst Time:t");
20 
21            scanf("%d", &burst_time[i]);
22 
23            temp[i] = burst_time[i];
24      }
25 
26      printf("nEnter Time Quantum:t");
27      scanf("%d", &time_quantum);
28      printf("nProcess IDttBurst Timet Turnaround Timet Waiting Timen");
29      for(total = 0, i = 0; x != 0;)
30      {
31            if(temp[i] <= time_quantum && temp[i] > 0)
32            {
33                  total = total + temp[i];
34                  temp[i] = 0;
35                  counter = 1;
36            }
37            else if(temp[i] > 0)
38            {
39                  temp[i] = temp[i] - time_quantum;
40                  total = total + time_quantum;
41            }
42            if(temp[i] == 0 && counter == 1)
43            {
44                  x--;
45                  printf("nProcess[%d]tt%dtt %dttt %d", i + 1, burst_time[i], total - arrival_time[i], total - arrival_time[i] - burst_time[i]);
46                  wait_time = wait_time + total - arrival_time[i] - burst_time[i];
47                  turnaround_time = turnaround_time + total - arrival_time[i];
48                  counter = 0;
49            }
50            if(i == limit - 1)
51            {
52                  i = 0;
53            }
54            else if(arrival_time[i + 1] <= total)
55            {
56                  i++;
57            }
58            else
59            {
60                  i = 0;
61            }
62      }
63 
64      average_wait_time = wait_time * 1.0 / limit;
65      average_turnaround_time = turnaround_time * 1.0 / limit;
66      printf("nnAverage Waiting Time:t%f", average_wait_time);
67      printf("nAvg Turnaround Time:t%fn", average_turnaround_time);
68      return 0;
69}
70
queries leading to this page
round robin code in cround robin scheduling algorithm c programrobin round cround robin program in cround robin scheduling program in cround robin coding problemround robin secduling algo programc program for round robin scheduling algorithmround robin scheduling program in c simpleimplement round robinround robin program in c 5cwhat is round robin algorithmround robin c programround robin scheduling in cround robin in cround robin scheduling in c languageround robin c coderound robin scheduling for processes programround robin scheduling algorithm program in cround robin c program with ascending orderimplementation of round robin using c round robin c coderound robin algorithm in cround robin scheduling code in cwaiting time for round robin c languageround robin algo with time qutantum programround robin scheduling implementation in c round robin scheduling c programround robin scheduling example in cround robin code cround robin coderr scheduling program in cc program round robin schedulinground robin execution using cc code for round robin algorthmround robin scheduling algorithm ccpu scheduling algorithm with context switching code c languagec program for round robin cpu schedulinground robin scheduling with cround robin implementation in cround robin algorrithmnin cwrite a program to implement the round robin 28rr 29 cpu scheduling algorithm c code for round robin scheduling algorithmround robin algorithmc program for round robin algorithmround robin scheduling c programround robin scheduling algorithm in cc roundrobinrobin round coderound robin scheduling using threads in crobin round scheduling program cround robin algorith in cround robinimplementation of round robin scheduling algorithm in cround robin cpu scheduling program in cc program for round robin 28rr 29 schedulingprogram for round robin scheduling in cround robin scheduling program round robin algorithm in c