Advertisement
Shailrshah

First Come First Serve 2.0

Jul 31st, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 12
  3. struct process{
  4.     char pid;
  5.     int at;
  6.     int et;
  7.     int ct;
  8.     int wt;
  9.     int tt;
  10. }pro[N] =   {
  11.                 {'A', 0, 10},
  12.                 {'B', 0, 3},
  13.                 {'C', 2, 2},
  14.                 {'D', 2, 1},
  15.                 {'E', 2, 4},
  16.                 {'F', 10, 5},
  17.                 {'G', 10, 7},
  18.                 {'H', 15, 8},
  19.                 {'I', 20, 10},
  20.                 {'J', 30, 9},
  21.                 {'K', 40, 3},
  22.                 {'L', 40, 2}
  23.             };
  24. void main(){
  25.     int i, time = 0, sumWT = 0, sumTT = 0;
  26.     for(i = 0; i < N;)
  27.         if(time >= pro[i].at){
  28.             pro[i].ct = time + pro[i].et;
  29.             time = pro[i].ct;
  30.             pro[i].wt = pro[i].ct - (pro[i].at + pro[i].et);
  31.             pro[i].tt = pro[i].ct - pro[i].at;
  32.             sumWT+=pro[i].wt;
  33.             sumTT+=pro[i].tt;
  34.             i++;
  35.         }
  36.         else time++;
  37.     printf("\tpid\tAT\tET\tCT\tWT\tTT\n");
  38.     for(i = 0; i < N; i++) printf("\t%c\t%d\t%d\t%d\t%d\t%d\n", pro[i].pid, pro[i].at, pro[i].et, pro[i].ct, pro[i].wt, pro[i].tt);
  39.     printf("\nThe average waiting time is %.2f\nThe average turn around time is %.2f\n", sumWT/(float)N, sumTT/(float)N);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement