GeezerVison is showing github.com — Add files via upload · bappasahabapi/Algorithm.cpp@a9640b3
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +59Lines changed: 59 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +#include<iostream> |
| 2 | + |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +int main() |
| 6 | +{ |
| 7 | + int n_process ,bt[20], wt[20], tat[20], avwt=0, avtat=0,avct =0, i, j; |
| 8 | + int ct[20]; |
| 9 | + cout<<"Enter total number of processes(maximum 20):"; |
| 10 | + cin>>n_process; |
| 11 | + |
| 12 | + cout<<"\nEnter Process Burst Time\n"; |
| 13 | + for(i=0; i<n_process ;i++) |
| 14 | + { |
| 15 | + cout<<"Process["<<i+1<<"]:"; |
| 16 | + cin>>bt[i]; |
| 17 | + } |
| 18 | + |
| 19 | + wt[0]=0; //waiting time for first process is 0 |
| 20 | + |
| 21 | + //calculating waiting time |
| 22 | + for(i=1;i<n_process;i++) |
| 23 | + { |
| 24 | + wt[i]=0; |
| 25 | + |
| 26 | + for(j=0; j<i; j++) |
| 27 | + wt[i]+=bt[j]; |
| 28 | + } |
| 29 | + |
| 30 | + //compleating time |
| 31 | + for(i=0; i<n_process; i++) |
| 32 | + { |
| 33 | + ct[i]= bt[i]; |
| 34 | + for(j=0; j<i; j++) |
| 35 | + ct[i]+=bt[j]; |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time\tCompleating Time\t "; |
| 40 | + |
| 41 | + //calculating turnaround time |
| 42 | + for(i=0; i<n_process; i++) |
| 43 | + { |
| 44 | + tat[i]=bt[i]+wt[i]; |
| 45 | + avwt+=wt[i]; |
| 46 | + avtat+=tat[i]; |
| 47 | + avct+=ct[i]; |
| 48 | + cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i]<<"\t\t"<<ct[i]; |
| 49 | + } |
| 50 | + |
| 51 | + avwt/=i; |
| 52 | + avtat/=i; |
| 53 | + cout<<"\n\nAverage Waiting Time:"<<avwt; |
| 54 | + cout<<"\nAverage Turnaround Time:"<<avtat; |
| 55 | + cout<<"\nAverage Compleating Time:"<<avct<<endl; |
| 56 | + |
| 57 | + return 0; |
| 58 | +} |
| 59 | + |