Advertisement
Shailrshah

First Come First Serve

Jul 30th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main(){
  4.     char pid[12], at[12]={0, 0, 2, 2, 2, 10, 10, 15, 20, 30, 40, 40}, et[12]={10,3,2,1,4,5,7,8,10,9,3,2}, ct[12], wt[12], tt[12];
  5.     int i, time, N=12, sumWT=0, sumTT=0;
  6.     float avgWT, avgTT;
  7.     clrscr();
  8.     for(i = 0; i < N; i++) pid[i] = i+ 65;
  9.     time = 0;
  10.     for(i = 0;;){
  11.         if(time >= at[i]){
  12.             ct[i] = time + et[i];
  13.             time = ct[i];
  14.             wt[i] = ct[i] - (at[i] + et[i]);
  15.             tt[i] = ct[i] - at[i];
  16.             i++;
  17.         }
  18.         else time++;
  19.         if(i == N) break;
  20.     }
  21.     printf("pid\tAT\tET\tCT\t\WT\tTT\n");
  22.     for(i = 0; i < N; i++){
  23.         printf("%c\t%d\t%d\t%d\t%d\t%d\n", pid[i], at[i], et[i], ct[i], wt[i], tt[i]);
  24.         sumWT+=wt[i];
  25.         sumTT+=tt[i];
  26.     }
  27.     avgWT = sumWT/12.0;
  28.     avgTT = sumTT/12.0;
  29.     printf("\nThe average waiting time is %.2f \n", avgWT);
  30.     printf("The average turn-around time is %.2f\n", avgTT);
  31.     getch();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement