Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define N 12
- struct process{
- char pid;
- int at;
- int et;
- int ct;
- int wt;
- int tt;
- }pro[N] = {
- {'A', 0, 10},
- {'B', 0, 3},
- {'C', 2, 2},
- {'D', 2, 1},
- {'E', 2, 4},
- {'F', 10, 5},
- {'G', 10, 7},
- {'H', 15, 8},
- {'I', 20, 10},
- {'J', 30, 9},
- {'K', 40, 3},
- {'L', 40, 2}
- };
- void main(){
- int i, time = 0, sumWT = 0, sumTT = 0;
- for(i = 0; i < N;)
- if(time >= pro[i].at){
- pro[i].ct = time + pro[i].et;
- time = pro[i].ct;
- pro[i].wt = pro[i].ct - (pro[i].at + pro[i].et);
- pro[i].tt = pro[i].ct - pro[i].at;
- sumWT+=pro[i].wt;
- sumTT+=pro[i].tt;
- i++;
- }
- else time++;
- printf("\tpid\tAT\tET\tCT\tWT\tTT\n");
- 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);
- printf("\nThe average waiting time is %.2f\nThe average turn around time is %.2f\n", sumWT/(float)N, sumTT/(float)N);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement