-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstComeFirstServe_array.c
More file actions
62 lines (57 loc) · 1.31 KB
/
Copy pathFirstComeFirstServe_array.c
File metadata and controls
62 lines (57 loc) · 1.31 KB
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
#include<stdio.h>
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
int main()
{
int n,at[50],bt[50],i,p[50],j,k,sum=0,ct[50]={0},tat[50],wt[50];
float ttat=0,twt=0,awt=0,atat=0;
printf("Enter no of process\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=i+1;
printf("Arrival Time of Process P%d: ",p[i]);
scanf("%d",&at[i]);
printf("Burst Time of Process P%d: ",p[i]);
scanf("%d",&bt[i]);
}
printf("Entered data can be represented in tabular form\n");
printf("\tProcess\t\tArrival Time\tBurst Time\n");
for(i=0;i<n;i++){
printf("\tP%d\t\t%d\t\t%d\n",p[i],at[i],bt[i]);
}
for(j=1;j<n;j++){
for(k=0;k<n-j;k++){
swap(&p[k],&p[k+1]);
if(at[k]>at[k+1]){
swap(&p[k],&p[k+1]);
swap(&at[k],&at[k+1]);
swap(&bt[k],&bt[k+1]);
}
}
}
for(i=0;i<n;i++){
sum=sum+bt[i];
ct[i]=ct[i]+sum;
tat[i]=ct[i]-at[i];
ttat=ttat+tat[i];
wt[i]=tat[i]-bt[i];
twt=twt+wt[i];
}
printf("After the completion of all processes\n");
printf("\tProcess\t\tArrival Time\tBurst Time\tCompletion Time\tTurnaround Time\tWaiting Time\n");
for(i=0;i<n;i++){
printf("\tP%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n",p[i],at[i],bt[i],ct[i],tat[i],wt[i]);
}
atat=ttat/n;
awt=twt/n;
printf("Average Turnaround Time=%0.2f",atat);
printf("\n");
printf("Average Waiting Time=%0.2f\n",awt);
return 0;
}