Created
October 11, 2023 14:43
-
-
Save rishabhgargg/5fba482a50a26f3fc6586e881d8425fe to your computer and use it in GitHub Desktop.
scaler
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
#include<stdio.h> | |
int main() | |
{ | |
int cnt,j,n,t,remain,flag=0,tq; | |
int wt=0,tat=0,at[10],bt[10],rt[10]; | |
printf("Enter Total Process:\t "); | |
scanf("%d",&n); | |
remain=n; | |
for(cnt=0;cnt<n;cnt++) | |
{ | |
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",cnt+1); | |
scanf("%d",&at[cnt]); | |
scanf("%d",&bt[cnt]); | |
rt[cnt]=bt[cnt]; | |
} | |
printf("Enter Time Quantum:\t"); | |
scanf("%d",&tq); | |
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n"); | |
for(t=0,cnt=0;remain!=0;) | |
{ | |
if(rt[cnt]<=tq && rt[cnt]>0) | |
{ | |
t+=rt[cnt]; | |
rt[cnt]=0; | |
flag=1; | |
} | |
else if(rt[cnt]>0) | |
{ | |
rt[cnt]-=tq; | |
t+=tq; | |
} | |
if(rt[cnt]==0 && flag==1) | |
{ | |
remain--; | |
printf("P[%d]\t|\t%d\t|\t%d\n",cnt+1,t-at[cnt],t-at[cnt]-bt[cnt]); | |
wt+=t-at[cnt]-bt[cnt]; | |
tat+=t-at[cnt]; | |
flag=0; | |
} | |
if(cnt==n-1) | |
cnt=0; | |
else if(at[cnt+1]<=t) | |
cnt++; | |
else | |
cnt=0; | |
} | |
printf("\nAverage Waiting Time= %f\n",wt*1.0/n); | |
printf("Avg Turnaround Time = %f",tat*1.0/n); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment