Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. //FCFS
  2.  
  3. #include<stdio.h>
  4. #include<string.h>
  5.  
  6. int sort(int ps[],int at[],int bt[],int n)
  7. {
  8. int j,k,temp;
  9. for(j=1;j<n;j++){
  10. for(k=1;k<n;k++){
  11. if(at[k]>at[k+1]){
  12. temp=at[k];
  13. at[k]=at[k+1];
  14. at[k+1]=temp;
  15.  
  16. temp=ps[k];
  17. ps[k]=ps[k+1];
  18. ps[k+1]=temp;
  19.  
  20. temp=bt[k];
  21. bt[k]=bt[k+1];
  22. bt[k+1]=temp;
  23. }
  24. }
  25. }
  26. }
  27.  
  28. int main()
  29. {
  30. int ps[50],at[50],bt[50],n,i,end=0;
  31.  
  32. printf("Input Number of Total Process\n");
  33.  
  34. scanf("%d",&n);
  35.  
  36. printf("Input Respectivly- Process > Arrival Time > Brust Time\nLike, 1 3 5\n");
  37.  
  38. for(i=1;i<=n;i++){
  39. scanf("%d %d %d",&ps[i],&at[i],&bt[i]); // Input Process, At, Bt
  40. }
  41.  
  42. sort(ps,at,bt,n); // Sort array accordingly Arrival time
  43.  
  44. printf("Process - Start_Time - End_Time - Wating_Time - Respons_Time\n");
  45. for(i=1;i<=n;i++){
  46. if(end>=at[i]){
  47. printf("P%d %d %d %d %d\n",ps[i],end,end+bt[i],end+bt[i]-at[i],end-at[i]); // Print Process
  48. end= end+bt[i];
  49. }
  50.  
  51. else{
  52. printf("Idol %d %d\n",end,end+at[i]); // Print Idol
  53. end= end+at[i];
  54. i--;
  55. }
  56.  
  57. }
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement