-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,71 @@ | ||
// C program for implementation of FCFS | ||
// scheduling | ||
#include<stdio.h> | ||
// Function to find the waiting time for all | ||
// processes | ||
void findWaitingTime(int processes[], int n, | ||
int bt[], int wt[]) | ||
{ | ||
// waiting time for first process is 0 | ||
wt[0] = 0; | ||
|
||
// calculating waiting time | ||
for (int i = 1; i < n ; i++ ) | ||
wt[i] = bt[i-1] + wt[i-1] ; | ||
} | ||
|
||
// Function to calculate turn around time | ||
void findTurnAroundTime( int processes[], int n, | ||
int bt[], int wt[], int tat[]) | ||
{ | ||
// calculating turnaround time by adding | ||
// bt[i] + wt[i] | ||
for (int i = 0; i < n ; i++) | ||
tat[i] = bt[i] + wt[i]; | ||
} | ||
|
||
//Function to calculate average time | ||
void findavgTime( int processes[], int n, int bt[]) | ||
{ | ||
int wt[n], tat[n], total_wt = 0, total_tat = 0; | ||
|
||
//Function to find waiting time of all processes | ||
findWaitingTime(processes, n, bt, wt); | ||
|
||
//Function to find turn around time for all processes | ||
findTurnAroundTime(processes, n, bt, wt, tat); | ||
|
||
//Display processes along with all details | ||
printf("Processes Burst time Waiting time Turn around time\n"); | ||
|
||
// Calculate total waiting time and total turn | ||
// around time | ||
for (int i=0; i<n; i++) | ||
{ | ||
total_wt = total_wt + wt[i]; | ||
total_tat = total_tat + tat[i]; | ||
printf(" %d ",(i+1)); | ||
printf(" %d ", bt[i] ); | ||
printf(" %d",wt[i] ); | ||
printf(" %d\n",tat[i] ); | ||
} | ||
int s=(float)total_wt / (float)n; | ||
int t=(float)total_tat / (float)n; | ||
printf("Average waiting time = %d",s); | ||
printf("\n"); | ||
printf("Average turn around time = %d ",t); | ||
} | ||
|
||
// Driver code | ||
int main() | ||
{ | ||
//process id's | ||
int processes[] = { 1, 2, 3}; | ||
int n = sizeof processes / sizeof processes[0]; | ||
|
||
//Burst time of all processes | ||
int burst_time[] = {10, 5, 8}; | ||
|
||
findavgTime(processes, n, burst_time); | ||
return 0; | ||
} |
This file contains 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,54 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp; | ||
float avg_wt,avg_tat; | ||
scanf("%d",&n); | ||
for(i=0;i<n;i++) | ||
{ | ||
scanf("%d",&bt[i]); | ||
p[i]=i+1; | ||
} | ||
for(i=0;i<n;i++) | ||
{ | ||
pos=i; | ||
for(j=i+1;j<n;j++) | ||
{ | ||
if(bt[j]<bt[pos]) | ||
pos=j; | ||
} | ||
temp=bt[i]; | ||
bt[i]=bt[pos]; | ||
bt[pos]=temp; | ||
|
||
temp=p[i]; | ||
p[i]=p[pos]; | ||
p[pos]=temp; | ||
} | ||
wt[0]=0; | ||
printf("wt: "); | ||
for(i=0;i<n;i++) | ||
{ | ||
wt[i]=0; | ||
for(j=0;j<i;j++) | ||
{ | ||
wt[i]+=bt[j]; | ||
} | ||
printf("%d ",wt[i]); | ||
total+=wt[i]; | ||
} | ||
avg_wt=(float)total/n; | ||
total=0; | ||
printf("\nTAT: "); | ||
for(i=0;i<n;i++) | ||
{ | ||
tat[i]=bt[i]+wt[i]; //calculate turnaround time | ||
total+=tat[i]; | ||
printf("%d ",tat[i]); | ||
} | ||
|
||
avg_tat=(float)total/n; | ||
printf("Average Waiting Time:%0.6f",avg_wt); | ||
printf("\nAverage Turnaround Time:%0.6f",avg_tat); | ||
return 0; | ||
} |