-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcfs.c
77 lines (72 loc) · 2.42 KB
/
fcfs.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>
#include<string.h>
void getData();
void fcfs();
void calculate();
void display();
int arrivalTime[10], burstTime[10], waitingTime[10], exitTime[10], turnAroundTime[10];
int n, temp, totalWaitingTime, totalTurnAroundTime;
float averageWaitingTime, averageTurnAroundTime;
char pName[20][20], temp1[20];
void main() {
getData();
fcfs();
calculate();
display();
}
void getData() {
printf("\nEnter the number of Process: ");
scanf("%d", &n);
for(int i = 0; i < n; i++) {
printf("\nEnter the Procees Name: ");
scanf("%s", &pName[i]);
printf("Enter the Arrival Time: ");
scanf("%d", &arrivalTime[i]);
printf("Enter the Burst Time: ");
scanf("%d", &burstTime[i]);
}
}
void fcfs() {
for(int i = 0; i < n; i++) {
for(int j = i + 1; j <= n; j++) {
if (arrivalTime[i] > arrivalTime[j]) {
temp = arrivalTime[j];
arrivalTime[j] = arrivalTime[i];
arrivalTime[i] = temp;
temp = burstTime[j];
burstTime[j] = burstTime[i];
burstTime[i] = temp;
strcpy(temp1, pName[j]);
strcpy(pName[j], pName[i]);
strcpy(pName[i], temp1);
}
}
}
}
void calculate() {
waitingTime[0] = 0;
turnAroundTime[0] = burstTime[0] + waitingTime[0];
exitTime[0] = burstTime[0] + arrivalTime[0];
totalTurnAroundTime = turnAroundTime[0];
totalWaitingTime = waitingTime[0];
for(int i = 1; i <= n; i++) {
waitingTime[i] = exitTime[i-1] - arrivalTime[i];
turnAroundTime[i] = burstTime[i] + waitingTime[i];
exitTime[i] = exitTime[i-1] + burstTime[i];
totalTurnAroundTime = totalTurnAroundTime + turnAroundTime[i];
totalWaitingTime = totalWaitingTime + waitingTime[i];
}
averageTurnAroundTime = (float) totalTurnAroundTime / n;
averageWaitingTime = (float) totalWaitingTime / n;
}
void display() {
printf("\n\nGantt Chart\n");
printf("\n__________________________________\n");
for(int i = 0; i <= n; i++)
printf("\t%s\t", pName[i]);
printf("\n__________________________________\n");
for(int i = 0; i <= n; i++)
printf("\t%d\t", exitTime[i]);
printf("\nAvarage TAT=%f", averageTurnAroundTime);
printf("\nAverage WT =%f", averageWaitingTime);
}