Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. //FCFS
  2. #include<stdio.h>
  3.  
  4. int main()
  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; //waiting time for first process is 0
  18.  
  19. //calculating waiting time
  20. for(i=1;i<n;i++)
  21. {
  22. wt[i]=0;
  23. for(j=0;j<i;j++)
  24. wt[i]=bt[j]+1;
  25. }
  26.  
  27. printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
  28.  
  29. //calculating turnaround time
  30. for(i=0;i<n;i++)
  31. {
  32. tat[i]=bt[i]+wt[i];
  33. avwt=wt[i]+1;
  34. avtat=tat[i]+1;
  35. printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
  36. }
  37.  
  38. avwt/=i;
  39. avtat/=i;
  40. printf("\n\nAverage Waiting Time:%d",avwt);
  41. printf("\nAverage Turnaround Time:%d",avtat);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement