Exp 2 Os
Exp 2 Os
Experiment No - 2
Objective :- Write a program to implement FCFS Scheduling
Algorithm and Shortest Job First Scheduling Algorithm.
Program:-
#include using namespace std;
int main()
{
int n;
cout << "Enter number of processes: ";
cin >> n;
int p[n], bt[n], wt[n], tat[n];
float total_wt = 0, total_tat = 0;
for (int i = 0; i < n; i++)
{
p[i] = i + 1;
cout << "Enter burst time for process " << i + 1 << ": ";
cin >> bt[i];
}
wt[0] = 0;
for (int i = 1; i < n; i++)
{
wt[i] = bt[i - 1] + wt[i - 1];
}
for (int i = 0; i < n; i++)
{
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i];
}
cout << "\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n";
cout << " " << p[i] << "\t" << bt[i] << "\t\t" << wt[i] << "\t\t" << tat[i]
<< "\n";
}
cout << "\nAverage Waiting Time = " << (total_wt / n) << " ms";
cout << "\nAverage Turnaround Time = " << (total_tat / n) << " ms\n";
return 0;
}
OUTPUT:-