Advertisement
Nahid8195

FCFS

Nov 29th, 2022
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4.  
  5. {
  6. int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
  7. printf("Enter total number of processes(maximum 20):");
  8. scanf("%d",&n);
  9.  
  10. printf("\nEnter Process Burst Time\n");
  11. for(i=0;i<n;i++)
  12. {
  13. printf("P[%d]:",i+1);
  14. scanf("%d",&bt[i]);
  15. }
  16.  
  17. wt[0]=0;
  18.  
  19. for(i=1;i<n;i++)
  20. {
  21. wt[i]=0;
  22. for(j=0;j<i;j++)
  23. wt[i]+=bt[j];
  24. }
  25.  
  26. printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
  27.  
  28. for(i=0;i<n;i++)
  29. {
  30. tat[i]=bt[i]+wt[i];
  31. avwt+=wt[i];
  32. avtat+=tat[i];
  33. printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
  34. }
  35.  
  36. avwt/=i;
  37. avtat/=i;
  38. printf("\n\nAverage Waiting Time:%d",avwt);
  39. printf("\nAverage Turnaround Time:%d",avtat);
  40.  
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement