# Scheduling algorithm

Apr 9th, 2019
409
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include<stdio.h>
2. int main()
3. {
4.   int count,j,n;
5.   int time,remaining;
6.   int flag=0,time_quantum=10;
7.   int waiting_time=0,turn_around_time=0,arrival_time[10],burst_time[10],rt[10];
8.   printf("\n\nEnter the Total number of Process:\t ");
9.   scanf("%d",&n);
10.   remaining=n;
11.   for(count=0;count<n;count++)
12.   {
13.     printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
14.     scanf("%d",&arrival_time[count]);
15.     scanf("%d",&burst_time[count]);
16.     rt[count]=burst_time[count];
17.   }
18.   printf("Enter Time Quantum:%d\t",time_quantum);
19.
20.   printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
21.   for(time=0,count=0;remaining!=0;)
22.   {
23.     if(rt[count]<=time_quantum && rt[count]>0)
24.     {
25.       time+=rt[count];
26.       rt[count]=0;
27.       flag=1;
28.     }
29.     else if(rt[count]>0)
30.     {
31.       rt[count]-=time_quantum;
32.       time+=time_quantum;
33.     }
34.     if(rt[count]==0 && flag==1)
35.     {
36.       remaining--;
37.       printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-arrival_time[count],time-arrival_time[count]-burst_time[count]);
38.       waiting_time+=time-arrival_time[count]-burst_time[count];
39.       turn_around_time+=time-arrival_time[count];
40.       flag=0;
41.     }
42.     if(count==n-1)
43.       count=0;
44.     else if(arrival_time[count+1]<=time)
45.       count++;
46.     else
47.       count=0;
48.   }
49.   printf("\nAverage Waiting Time= %f\n",waiting_time*1.0/n);
50.   printf("Avg Turnaround Time = %f",turn_around_time*1.0/n);
51.
52.   return 0;
53. }
RAW Paste Data