# FCFS CPU Scheduling

Here given code implementation process.

``````// C program
// Implementation of First Come First Served (FCFS) Scheduling
#include <stdio.h>

//This is calculating the average time by using given process and burst time
void find_avg_time(int processes[], int burst_time[], int n)
{
// Auxiliary space to store waiting time and turnaround time
int turnaround_time[n];
int waiting_time[n];
//Resultant variable
double total_waiting_time = 0;
double total_turnaround_time = 0;
//Loop control variable
int i = 0;
// Initial waiting time are zero
waiting_time[i] = 0;
// Calculate waiting time and turnaround time
for (i = 0; i < n; ++i)
{
// Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i];
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i];
}
}
printf(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)");
// Display process ,burst time, waiting time, turn around time ,
// And calculate the average waiting time and average turn around time
for (i = 0; i < n; i++)
{
// Calculate waiting time
total_waiting_time += waiting_time[i];
// Calculate turnaround time
total_turnaround_time += turnaround_time[i];
printf("\n  %d \t\t%d \t\t%d \t\t%d ", (i + 1), burst_time[i], waiting_time[i], turnaround_time[i]);
}
//Display Result
printf("\n Average Waiting Time  : %lf", (total_waiting_time / n));
printf("\n Average Turn Around Time  : %lf\n", (total_turnaround_time / n));
}
int main()
{
//Process set
int processes[] = {
1,
2,
3,
4,
5
};
//Burst time of process set
int burst_time[] = {
7,
9,
11,
4,
8
};
// Assume that size of process and burst time is equal
// Get size
int n = sizeof processes / sizeof processes;
find_avg_time(processes, burst_time, n);
return 0;
}``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time  : 16.200000
Average Turn Around Time  : 24.000000``````
``````// Java program
// Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling
{
//This is calculating the average time by using given process and burst time
public void find_avg_time(int[] processes, int[] burst_time, int n)
{
// Auxiliary space to store waiting time and turnaround time
int[] turnaround_time = new int[n];
int[] waiting_time = new int[n];
//Resultant variable
double total_waiting_time = 0;
double total_turnaround_time = 0;
//Loop control variable
int i = 0;
// Initial waiting time are zero
waiting_time[i] = 0;
// Calculate waiting time and turnaround time
for (i = 0; i < n; ++i)
{
// Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i];
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i];
}
}
System.out.print(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)");
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
for (i = 0; i < n; i++)
{
// Calculate waiting time
total_waiting_time += waiting_time[i];
// Calculate turnaround time
total_turnaround_time += turnaround_time[i];
System.out.print("\n " + (i + 1) + " \t\t" + burst_time[i] + " \t\t" + waiting_time[i] + " \t\t" + turnaround_time[i] + " ");
}
//Display Result
System.out.print("\n Average Waiting Time : " + (total_waiting_time / n));
System.out.print("\n Average Turn Around Time : " + (total_turnaround_time / n) + "\n");
}
public static void main(String args[])
{
FcfsScheduling obj = new FcfsScheduling();
//Process set
int[] processes = {
1,
2,
3,
4,
5
};
//Burst time of process set
int[] burst_time = {
7,
9,
11,
4,
8
};
// Assume that size of process and burst time is equal
// Get size
int n = processes.length;
obj.find_avg_time(processes, burst_time, n);
}
}``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24.0``````
``````//Include header file
#include <iostream>
using namespace std;

// C++ program
// Implementation of First Come First Served (FCFS) Scheduling

class FcfsScheduling
{
public:
//This is calculating the average time by using given process and burst time
void find_avg_time(int processes[], int burst_time[], int n)
{
// Auxiliary space to store waiting time and turnaround time
int turnaround_time[n];
int waiting_time[n];
//Resultant variable
double total_waiting_time = 0;
double total_turnaround_time = 0;
//Loop control variable
int i = 0;
// Initial waiting time are zero
waiting_time[i] = 0;
// Calculate waiting time and turnaround time
for (i = 0; i < n; ++i)
{
// Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i];
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i];
}
}
cout << " (Process) (Burst Time) (Waiting Time) (Turn Around Time)";
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
for (i = 0; i < n; i++)
{
// Calculate waiting time
total_waiting_time += waiting_time[i];
// Calculate turnaround time
total_turnaround_time += turnaround_time[i];
cout << "\n " << (i + 1) << " \t\t" << burst_time[i] << " \t\t" << waiting_time[i] << " \t\t" << turnaround_time[i] << " ";
}
//Display Result
cout << "\n Average Waiting Time : " << (total_waiting_time / n);
cout << "\n Average Turn Around Time : " << (total_turnaround_time / n) << "\n";
}
};
int main()
{
FcfsScheduling obj = FcfsScheduling();
//Process set
int processes[] = {
1 , 2 , 3 , 4 , 5
};
//Burst time of process set
int burst_time[] = {
7 , 9 , 11 , 4 , 8
};
// Assume that size of process and burst time is equal
// Get size
int n = sizeof(processes) / sizeof(processes);
obj.find_avg_time(processes, burst_time, n);
return 0;
}``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24``````
``````//Include namespace system
using System;
// C# program
// Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling
{
//This is calculating the average time by using given process and burst time
public void find_avg_time(int[] processes, int[] burst_time, int n)
{
// Auxiliary space to store waiting time and turnaround time
int[] turnaround_time = new int[n];
int[] waiting_time = new int[n];
//Resultant variable
double total_waiting_time = 0;
double total_turnaround_time = 0;
//Loop control variable
int i = 0;
// Initial waiting time are zero
waiting_time[i] = 0;
// Calculate waiting time and turnaround time
for (i = 0; i < n; ++i)
{
// Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i];
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i];
}
}
Console.Write(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)");
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
for (i = 0; i < n; i++)
{
// Calculate waiting time
total_waiting_time += waiting_time[i];
// Calculate turnaround time
total_turnaround_time += turnaround_time[i];
Console.Write("\n " + (i + 1) + " \t\t" + burst_time[i] + " \t\t" + waiting_time[i] + " \t\t" + turnaround_time[i] + " ");
}
//Display Result
Console.Write("\n Average Waiting Time : " + (total_waiting_time / n));
Console.Write("\n Average Turn Around Time : " + (total_turnaround_time / n) + "\n");
}
public static void Main(String []args)
{
FcfsScheduling obj = new FcfsScheduling();
//Process set
int[] processes = {
1 , 2 , 3 , 4 , 5
};
//Burst time of process set
int[] burst_time = {
7 , 9 , 11 , 4 , 8
};
// Assume that size of process and burst time is equal
// Get size
int n = processes.Length;
obj.find_avg_time(processes, burst_time, n);
}
}``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24``````
``````<?php
// Php program
// Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling
{
//This is calculating the average time by using given process and burst time
public	function find_avg_time( & \$processes, & \$burst_time, \$n)
{
// Auxiliary space to store waiting time and turnaround time
\$turnaround_time = array_fill(0, \$n, 0);
\$waiting_time = array_fill(0, \$n, 0);
//Resultant variable
\$total_waiting_time = 0;
\$total_turnaround_time = 0;
//Loop control variable
\$i = 0;
// Initial waiting time are zero
\$waiting_time[\$i] = 0;
// Calculate waiting time and turnaround time
for (\$i = 0; \$i < \$n; ++\$i)
{
// Get turn around time for ith processes
\$turnaround_time[\$i] = \$burst_time[\$i] + \$waiting_time[\$i];
if (\$i + 1 < \$n)
{
// Get waiting time of next processes
\$waiting_time[\$i + 1] = \$turnaround_time[\$i];
}
}
echo " (Process) (Burst Time) (Waiting Time) (Turn Around Time)";
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
for (\$i = 0; \$i < \$n; \$i++)
{
// Calculate waiting time
\$total_waiting_time += \$waiting_time[\$i];
// Calculate turnaround time
\$total_turnaround_time += \$turnaround_time[\$i];
echo "\n ". (\$i + 1) ." \t\t". \$burst_time[\$i] ." \t\t". \$waiting_time[\$i] ." \t\t". \$turnaround_time[\$i] ." ";
}
//Display Result
echo "\n Average Waiting Time : ". (\$total_waiting_time / \$n);
echo "\n Average Turn Around Time : ". (\$total_turnaround_time / \$n) ."\n";
}
}

function main()
{
\$obj = new FcfsScheduling();
//Process set
\$processes = array(1, 2, 3, 4, 5);
//Burst time of process set
\$burst_time = array(7, 9, 11, 4, 8);
// Assume that size of process and burst time is equal
// Get size
\$n = count(\$processes);
\$obj->find_avg_time(\$processes, \$burst_time, \$n);
}
main();``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24``````
``````// Node Js program
// Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling
{
//This is calculating the average time by using given process and burst time
find_avg_time(processes, burst_time, n)
{
// Auxiliary space to store waiting time and turnaround time
var turnaround_time = Array(n).fill(0);
var waiting_time = Array(n).fill(0);
//Resultant variable
var total_waiting_time = 0;
var total_turnaround_time = 0;
//Loop control variable
var i = 0;
// Initial waiting time are zero
waiting_time[i] = 0;
// Calculate waiting time and turnaround time
for (i = 0; i < n; ++i)
{
// Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i];
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i];
}
}
process.stdout.write(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)");
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
for (i = 0; i < n; i++)
{
// Calculate waiting time
total_waiting_time += waiting_time[i];
// Calculate turnaround time
total_turnaround_time += turnaround_time[i];
process.stdout.write("\n " + (i + 1) + " \t\t" + burst_time[i] + " \t\t" + waiting_time[i] + " \t\t" + turnaround_time[i] + " ");
}
//Display Result
process.stdout.write("\n Average Waiting Time : " + ((total_waiting_time / n)));
process.stdout.write("\n Average Turn Around Time : " + ((total_turnaround_time / n)) + "\n");
}
}

function main()
{
var obj = new FcfsScheduling();
//Process set
var processes = [1, 2, 3, 4, 5];
//Burst time of process set
var burst_time = [7, 9, 11, 4, 8];
// Assume that size of process and burst time is equal
// Get size
var n = processes.length;
obj.find_avg_time(processes, burst_time, n);
}
main();``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24``````
``````#  Python 3 program
#  Implementation of First Come First Served (FCFS) Scheduling

class FcfsScheduling :
# This is calculating the average time by using given process and burst time
def find_avg_time(self, processes, burst_time, n) :
#  Auxiliary space to store waiting time and turnaround time
turnaround_time =  * n
waiting_time =  * n
# Resultant variable
total_waiting_time = 0
total_turnaround_time = 0
# Loop control variable
i = 0
#  Initial waiting time are zero
waiting_time[i] = 0
#  Calculate waiting time and turnaround time
while (i < n) :
#  Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i]
if (i + 1 < n) :
#  Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i]

i += 1

print(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)", end = "")
#  Display process ,burst time, waiting time, turn around time
#  And calculate the average waiting time and average turn around time
i = 0
while (i < n) :
#  Calculate waiting time
total_waiting_time += waiting_time[i]
#  Calculate turnaround time
total_turnaround_time += turnaround_time[i]
print("\n ", (i + 1) ," \t\t", burst_time[i] ," \t\t", waiting_time[i] ," \t\t", turnaround_time[i] ," ", end = "")
i += 1

# Display Result
print("\n Average Waiting Time : ", (total_waiting_time / n), end = "")
print("\n Average Turn Around Time : ", (total_turnaround_time / n) ,"\n", end = "")

def main() :
obj = FcfsScheduling()
# Process set
processes = [1, 2, 3, 4, 5]
# Burst time of process set
burst_time = [7, 9, 11, 4, 8]
#  Assume that size of process and burst time is equal
#  Get size
n = len(processes)
obj.find_avg_time(processes, burst_time, n)

if __name__ == "__main__": main()``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1  		 7  		 0  		 7
2  		 9  		 7  		 16
3  		 11  		 16  		 27
4  		 4  		 27  		 31
5  		 8  		 31  		 39
Average Waiting Time :  16.2
Average Turn Around Time :  24.0``````
``````#  Ruby program
#  Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling

# This is calculating the average time by using given process and burst time
def find_avg_time(processes, burst_time, n)

#  Auxiliary space to store waiting time and turnaround time
turnaround_time = Array.new(n) {0}
waiting_time = Array.new(n) {0}
# Resultant variable
total_waiting_time = 0.0
total_turnaround_time = 0.0
# Loop control variable
i = 0
#  Initial waiting time are zero
waiting_time[i] = 0
#  Calculate waiting time and turnaround time
while (i < n)

#  Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i]
if (i + 1 < n)

#  Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i]
end
i += 1
end
print(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)")
#  Display process ,burst time, waiting time, turn around time
#  And calculate the average waiting time and average turn around time
i = 0
while (i < n)

#  Calculate waiting time
total_waiting_time += waiting_time[i]
#  Calculate turnaround time
total_turnaround_time += turnaround_time[i]
print("\n ", (i + 1) ," \t\t", burst_time[i] ," \t\t", waiting_time[i] ," \t\t", turnaround_time[i] ," ")
i += 1
end
# Display Result
print("\n Average Waiting Time : ", (total_waiting_time / n))
print("\n Average Turn Around Time : ", (total_turnaround_time / n) ,"\n")
end
end
def main()

obj = FcfsScheduling.new()
# Process set
processes = [1, 2, 3, 4, 5]
# Burst time of process set
burst_time = [7, 9, 11, 4, 8]
#  Assume that size of process and burst time is equal
#  Get size
n = processes.length
obj.find_avg_time(processes, burst_time, n)
end
main()``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24.0
``````
``````// Scala program
// Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling
{
//This is calculating the average time by using given process and burst time
def find_avg_time(processes: Array[Int], burst_time: Array[Int], n: Int): Unit = {
// Auxiliary space to store waiting time and turnaround time
var turnaround_time: Array[Int] = Array.fill[Int](n)(0);
var waiting_time: Array[Int] = Array.fill[Int](n)(0);
//Resultant variable
var total_waiting_time: Double = 0;
var total_turnaround_time: Double = 0;
//Loop control variable
var i: Int = 0;
// Initial waiting time are zero
waiting_time(i) = 0;
// Calculate waiting time and turnaround time
while (i < n)
{
// Get turn around time for ith processes
turnaround_time(i) = burst_time(i) + waiting_time(i);
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time(i + 1) = turnaround_time(i);
}
i += 1;
}
print(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)");
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
i = 0;
while (i < n)
{
// Calculate waiting time
total_waiting_time += waiting_time(i);
// Calculate turnaround time
total_turnaround_time += turnaround_time(i);
print("\n " + (i + 1) + " \t\t" + burst_time(i) + " \t\t" + waiting_time(i) + " \t\t" + turnaround_time(i) + " ");
i += 1;
}
//Display Result
print("\n Average Waiting Time : " + ((total_waiting_time / n)));
print("\n Average Turn Around Time : " + ((total_turnaround_time / n)) + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: FcfsScheduling = new FcfsScheduling();
//Process set
var processes: Array[Int] = Array(1, 2, 3, 4, 5);
//Burst time of process set
var burst_time: Array[Int] = Array(7, 9, 11, 4, 8);
// Assume that size of process and burst time is equal
// Get size
var n: Int = processes.length;
obj.find_avg_time(processes, burst_time, n);
}
}``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1 		7 		0 		7
2 		9 		7 		16
3 		11 		16 		27
4 		4 		27 		31
5 		8 		31 		39
Average Waiting Time : 16.2
Average Turn Around Time : 24.0``````
``````// Swift program
// Implementation of First Come First Served (FCFS) Scheduling
class FcfsScheduling
{
//This is calculating the average time by using given process and burst time
func find_avg_time(_ processes: [Int], _ burst_time: [Int], _ n: Int)
{
// Auxiliary space to store waiting time and turnaround time
var turnaround_time: [Int] = Array(repeating: 0, count: n);
var waiting_time: [Int] = Array(repeating: 0, count: n);
//Resultant variable
var total_waiting_time: Double = 0;
var total_turnaround_time: Double = 0;
//Loop control variable
var i: Int = 0;
// Initial waiting time are zero
waiting_time[i] = 0;
// Calculate waiting time and turnaround time
while (i < n)
{
// Get turn around time for ith processes
turnaround_time[i] = burst_time[i] + waiting_time[i];
if (i + 1 < n)
{
// Get waiting time of next processes
waiting_time[i + 1] = turnaround_time[i];
}
i += 1;
}
print(" (Process) (Burst Time) (Waiting Time) (Turn Around Time)", terminator: "");
// Display process ,burst time, waiting time, turn around time
// And calculate the average waiting time and average turn around time
i = 0;
while (i < n)
{
// Calculate waiting time
total_waiting_time += Double(waiting_time[i]);
// Calculate turnaround time
total_turnaround_time += Double(turnaround_time[i]);
print("\n ", (i + 1) ," \t\t", burst_time[i] ," \t\t", waiting_time[i] ," \t\t", turnaround_time[i] ," ", terminator: "");
i += 1;
}
//Display Result
print("\n Average Waiting Time : ", (total_waiting_time / Double(n)), terminator: "");
print("\n Average Turn Around Time : ", (total_turnaround_time / Double(n)) ,"\n", terminator: "");
}
}
func main()
{
let obj: FcfsScheduling = FcfsScheduling();
//Process set
let processes: [Int] = [1, 2, 3, 4, 5];
//Burst time of process set
let burst_time: [Int] = [7, 9, 11, 4, 8];
// Assume that size of process and burst time is equal
// Get size
let n: Int = processes.count;
obj.find_avg_time(processes, burst_time, n);
}
main();``````

#### Output

`````` (Process) (Burst Time) (Waiting Time) (Turn Around Time)
1  		 7  		 0  		 7
2  		 9  		 7  		 16
3  		 11  		 16  		 27
4  		 4  		 27  		 31
5  		 8  		 31  		 39
Average Waiting Time :  16.2
Average Turn Around Time :  24.0``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.