Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. void main()
  5. {
  6. int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];
  7. int totwt=0,totta=0;
  8. float awt,ata;
  9. char pn[10][10],t[10];
  10. //clrscr();
  11. printf("Enter the number of process:");
  12. scanf("%d",&n);
  13. for(i=0; i<n; i++)
  14. {
  15. printf("Enter process name,arrivaltime,execution time & priority:");
  16. //flushall();
  17. scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]);
  18. }
  19. for(i=0; i<n; i++)
  20. for(j=0; j<n; j++)
  21. {
  22. if(p[i]<p[j])
  23. {
  24. temp=p[i];
  25. p[i]=p[j];
  26. p[j]=temp;
  27. temp=at[i];
  28. at[i]=at[j];
  29. at[j]=temp;
  30. temp=et[i];
  31. et[i]=et[j];
  32. et[j]=temp;
  33. strcpy(t,pn[i]);
  34. strcpy(pn[i],pn[j]);
  35. strcpy(pn[j],t);
  36. }
  37. }
  38. for(i=0; i<n; i++)
  39.  
  40. {
  41.  
  42. if(i==0)
  43. {
  44. st[i]=at[i];
  45. wt[i]=st[i]-at[i];
  46. ft[i]=st[i]+et[i];
  47. ta[i]=ft[i]-at[i];
  48. }
  49. else
  50. {
  51. st[i]=ft[i-1];
  52. wt[i]=st[i]-at[i];
  53. ft[i]=st[i]+et[i];
  54. ta[i]=ft[i]-at[i];
  55. }
  56. totwt+=wt[i];
  57. totta+=ta[i];
  58. }
  59. awt=(float)totwt/n;
  60. ata=(float)totta/n;
  61. printf("\nPname\tarrivaltime\texecutiontime\tpriority\twaitingtime\ttatime");
  62. for(i=0; i<n; i++)
  63. printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]);
  64. printf("\nAverage waiting time is:%f",awt);
  65. printf("\nAverage turnaroundtime is:%f",ata);
  66. getch();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement