Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<conio.h>
- #include<stdio.h>
- void main()
- {
- int burst[10],pid[10],priority[10],wt[10],total, n, i, j, temp;
- clrscr();
- printf("\nPriority Scheduling");
- printf("\nEnter Number of Processes:");
- scanf("%d",&n);
- printf("\nEnter %d Processes Details\n\n",n);
- for(i=0;i<n;i++)
- {
- printf("\nEnter Process %d ID:",i+1);
- scanf("%d",&pid[i]);
- printf("\nEnter Process %d Burst Time:",i+1);
- scanf("%d",&burst[i]);
- printf("\nEnter Process %d Priority:",i+1);
- scanf("%d",&priority[i]);
- }
- for(i=0;i<n-1;i++)
- {
- for(j=i+1;j<n;j++)
- {
- if(priority[i]<priority[j])
- {
- //Swapping Processes Based on Priority
- temp=priority[i];
- priority[i]=priority[j];
- priority[j]=temp;
- //Swapping Process ID Accordingly
- temp=pid[i];
- pid[i]=pid[j];
- pid[j]=temp;
- //Swapping Burst Time
- temp=burst[i];
- burst[i]=burst[j];
- burst[j]=temp;
- }
- }
- }
- //Waiting time for the First Process is zero.
- wt[0]=0;
- for(i=1;i<n;i++)
- {
- wt[i]=wt[i-1]+burst[i-1];
- total=total+wt[i];
- }
- printf("\nPRIORITY\tP_ID\tP_TIME\tWT_TIME\n");
- for(i=0;i<n;i++)
- {
- printf("%d\t%d\t%d\t%d\n",priority[i],pid[i],burst[i],wt[i]);
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement