Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int bt[20],p[20],wt[20],pr[20],i,j,n,pos,temp;
- float total=0,avg_wt;
- printf("Enter Total Number of Process:");
- scanf("%d",&n);
- printf("\nEnter Burst Time and Priority\n");
- for(i=0;i<n;i++)
- {
- printf("\nP[%d]\n",i+1);
- printf("Burst Time:");
- scanf("%d",&bt[i]);
- printf("Priority:");
- scanf("%d",&pr[i]);
- p[i]=i+1;
- }
- for(i=0;i<n;i++)
- {
- pos=i;
- for(j=i+1;j<n;j++)
- {
- if(pr[j]>pr[pos])
- pos=j;
- }
- temp=pr[i];
- pr[i]=pr[pos];
- pr[pos]=temp;
- temp=bt[i];
- bt[i]=bt[pos];
- bt[pos]=temp;
- temp=p[i];
- p[i]=p[pos];
- p[pos]=temp;
- }
- wt[0]=0;
- for(i=1;i<n;i++)
- {
- wt[i]=0;
- for(j=0;j<i;j++)
- wt[i]+=bt[j];
- total+=wt[i];
- }
- avg_wt=total/n;
- printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
- for(i=0;i<n;i++)
- {
- printf("\nP[%d]\t\t %d\t\t %d\t\t\t",p[i],bt[i],wt[i]);
- }
- printf("\n\nAverage Waiting Time=%f",avg_wt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement