Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int n,i,j,pid[10],bt[10],wt[10],tat[10],total_wt,total_tat,pos,temp,total=0;
- float avg_wt, avg_tat;
- printf("Enter the Size: ");
- scanf("%d",&n);
- printf("\nEnter the burst time: ");
- for(i=0; i<n; i++)
- {
- scanf("%d",&bt[i]);
- pid[i]=i;
- }
- for(i=0; i<n; i++)
- {
- pos=i;
- for(j=i+1; j<n; j++)
- {
- if(bt[j]<bt[pos])
- pos=j;
- }
- temp=bt[i];
- bt[i]=bt[pos];
- bt[pos]=temp;
- temp=pid[i];
- pid[i]=pid[pos];
- pid[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=(float)total/n;
- total=0;
- printf("\nProcess \t Burst T \tWaiting T \tTurnaround T");
- for(i=0; i<n; i++)
- {
- tat[i]=bt[i]+wt[i];
- total+=tat[i];
- printf("\np%\d\t\t %d\t\t %d\t\t\t%d",pid[i],bt[i],wt[i],tat[i]);
- }
- avg_tat=(float)total/n;
- printf("\n\nAverage waiting Time= %f",avg_wt);
- printf("\nAverage turnaround Time= %f\n",avg_tat);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement