FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Create fcfs.cpp by Nandhika2003 · Pull Request #366 · AllAlgorithms/cpp · GitHub

This repository was archived by the owner on Sep 7, 2025. It is now read-only.
/ cpp Public archive
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
44 changes: 44 additions & 0 deletions algorithms/scheduling-algorithms/fcfs.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include<iostream>
using namespace std;

void findWaitingTime(int processes[], int n, int bt[], int wt[]) {
wt[0] = 0;
for (int i = 1; i < n ; i++ )
wt[i] = bt[i-1] + wt[i-1] ;
}

void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[]) {
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}

void findavgTime( int processes[], int n, int bt[]) {
int wt[n], tat[n], total_wt = 0, total_tat = 0;


findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt, tat);


cout << "Processes "<< " Burst time "<< " Completion time "
<< " Turn around time " << " Waiting time\n";
for (int i=0; i<n; i++) {
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i+1 << "\t\t" << bt[i] <<"\t\t"
<< tat[i] <<"\t\t " << tat[i] <<"\t\t " << wt[i] <<endl;
}

cout << "Average waiting time = " << (float)total_wt / (float)n;
cout << "\nAverage turn around time = " << (float)total_tat / (float)n <<endl;
}

int main() {
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];

int burst_time[] = {24, 3, 3};

findavgTime(processes, n, burst_time);
return 0;
}

Back | FazBrowse Home | New Git URL