-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriority_scheduling.cpp
64 lines (52 loc) · 1.35 KB
/
priority_scheduling.cpp
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
56
57
58
59
60
61
62
63
64
#include<stdio.h>
int main()
{
int i,j,n,temp,temp1,total_turnaround,waiting_time=0;
int waiting=0;
int turnaround=0;
printf("enter total processes ");
scanf("%d",&n);
int process[n];
int burst_time[n];
int priority[n];
int temp2;
int turng;
for(i=0;i<n;i++)
{
printf("Enter process number:- ");
scanf("%d",&process[i]);
printf("Enter the priority of process %d ",i+1);
scanf("%d",&priority[i]);
printf("Enter burst time of process %d ",i+1);
scanf("%d",&burst_time[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(priority[i]<priority[j])
{
temp=burst_time[i];
burst_time[i]= burst_time[j];
burst_time[j]=temp;
temp2=priority[i];
priority[i]=priority[j];
priority[j]=temp2;
temp1=process[i];
process[i]=process[j];
process[j]=temp1;
}
}
}
printf(" Process priority Burst Time WaitTime Turn Around Time\n");
for(int i=0;i<n;i++)
{
turnaround=turnaround+burst_time[i];
total_turnaround=turnaround+total_turnaround;
printf("| %d | %d | %d | %d | %d |\n",process[i],priority[i],burst_time[i],waiting,turnaround);
waiting_time=waiting+waiting_time;
waiting=waiting+burst_time[i];
}
printf("\n avg waiting time- %d",(waiting_time/n));
printf("\n avg turnaround time- %d",(total_turnaround/n));
}