Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include<conio.h>
  2. #include<stdio.h>
  3.  
  4. void main()
  5. {
  6. int burst[10],pid[10],priority[10],wt[10],total, n, i, j, temp;
  7. clrscr();
  8. printf("\nPriority Scheduling");
  9. printf("\nEnter Number of Processes:");
  10. scanf("%d",&n);
  11. printf("\nEnter %d Processes Details\n\n",n);
  12. for(i=0;i<n;i++)
  13. {
  14. printf("\nEnter Process %d ID:",i+1);
  15. scanf("%d",&pid[i]);
  16. printf("\nEnter Process %d Burst Time:",i+1);
  17. scanf("%d",&burst[i]);
  18. printf("\nEnter Process %d Priority:",i+1);
  19. scanf("%d",&priority[i]);
  20. }
  21.  
  22. for(i=0;i<n-1;i++)
  23. {
  24. for(j=i+1;j<n;j++)
  25. {
  26. if(priority[i]<priority[j])
  27. {
  28. //Swapping Processes Based on Priority
  29. temp=priority[i];
  30. priority[i]=priority[j];
  31. priority[j]=temp;
  32. //Swapping Process ID Accordingly
  33. temp=pid[i];
  34. pid[i]=pid[j];
  35. pid[j]=temp;
  36. //Swapping Burst Time
  37. temp=burst[i];
  38. burst[i]=burst[j];
  39. burst[j]=temp;
  40. }
  41.  
  42. }
  43. }
  44. //Waiting time for the First Process is zero.
  45. wt[0]=0;
  46. for(i=1;i<n;i++)
  47. {
  48. wt[i]=wt[i-1]+burst[i-1];
  49. total=total+wt[i];
  50. }
  51. printf("\nPRIORITY\tP_ID\tP_TIME\tWT_TIME\n");
  52. for(i=0;i<n;i++)
  53. {
  54. printf("%d\t%d\t%d\t%d\n",priority[i],pid[i],burst[i],wt[i]);
  55. }
  56. getch();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement