code
code
// scheduling
#include<iostream>
// processes
wt[0] = 0;
// bt[i] + wt[i]
<< " Waiting time " << " Turn around time\n";
// around time
cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
<< wt[i] <<"\t\t " << tat[i] <<endl;
// Driver code
int main()
//process id's
findavgTime(processes, n, burst_time);
return 0;
}
#include <iostream>
using namespace std;
int main() {
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
cout << "P BT WT TAT" << endl;
avg_tat = (float)total / n;
cout << "Average Waiting Time= " << avg_wt << endl;
cout << "Average Turnaround Time= " << avg_tat << endl;
}
Sjf
#include <iostream>
int main() {
int A[100][4];
cin >> n;
index = i;
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
A[0][2] = 0;
A[i][2] = 0;
A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
// data.
total += A[i][3];
cout << "P" << A[i][0] << " " << A[i][1] << " " << A[i][2] << " " << A[i][3] << endl;
avg_tat = (float)total / n;
cout << "Average Waiting Time= " << avg_wt << endl;
cout << "Average Turnaround Time= " << avg_tat << endl;
Priority
#include<iostream>
int main()
{ int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
cout<<"Enter total number of processes(maximum 20):";
cin>>n;
for(i=0;i<n;i++)
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\
t\t"<<tat[i];
avwt/=i;
avtat/=i;
return 0;
RR
#include <climits>
#include <iostream>
struct Process
{
};
int quant;
int main()
int n, i, j;
// Taking Input
cin >> n;
Process p[n];
cout << "Enter the Arrival time of processes: " << endl;
// Declaring variables
int c = n, s[n][20];
b[i] = p[i].BT;
a[i] = p[i].AT;
s[i][j] = -1;
tot_wt = 0;
tot_tat = 0;
mini = INT_MAX;
flag = false;
index = i;
mini = a[i];
flag = true;
if (!flag)
time++;
continue;
j++;
if (s[index][j] == -1)
s[index][j] = time;
p[index].ST[j] = time;
time += b[index];
b[index] = 0;
else
time += quant;
b[index] -= quant;
if (b[index] > 0)
{
if (b[index] == 0)
c--;
p[index].FT = time;
tot_wt += p[index].WT;
tot_tat += p[index].TAT;
// Printing output
j = 0;
while (j != 10)
j += 1;
cout << " ";
j = 0;
int v = 0;
j++;
v += 3;
while (v != 40)
v += 1;
cout << "The average wait time is: " << avg_wt << endl;
cout << "The average TurnAround time is: " << avg_tat << endl;
return 0;