// Service algorithm # include <stdio. h> # include <stdlib. h> # define N 24 Main () {int I, n; int reachtime [N], needtime [N], starttime [N], finishtime [N], cycletime [N]; // turnover time float cltime [N]; // weighted turnover time char name [N]; printf ("\ n enter the number of jobs: "); scanf (" % d ", & N); for (I = 0; I <n; I ++) {printf (" \ n name :"); scanf ("% s", & name [I]); printf ("\ n reachtime:"); scanf ("% d", & reachtime [I]); printf ("\ n needtime:"); scanf ("% d", & needtime [I]); if (I = 0) {starttime [I] = reachtime [I];} finishtime [I] = starttime [I] + needtime [I]; cycletime [I] = finishtime [I]-reachtime [I]; cltime [I] = cycletime [I] * 1.0/needtime [I]; starttime [I + 1] = finishtime [I];} printf ("\ n \ tname reachtime needtime startime finishtime cycletime cltime"); for (I = 0; I <N; I ++) {printf ("\ n \ t % C \ t % d \ t %. 2f ", name [I], reachtime [I], needtime [I], starttime [I], finishtime [I], cycletime [I], cltime [I]) ;}}
Running result:
// The shortest job priority algorithm # include <stdio. h> # include <stdlib. h> # define N 24 Main () {int I, j, N, temp; int reachtime [N], needtime [N], starttime [N], finishtime [N], cycletime [N]; float cltime [N]; char name [N], ctemp; printf ("\ n enter the number of jobs:"); scanf ("% d ", & N); for (I = 0; I <n; I ++) {printf ("\ n name:"); scanf ("% s ", & name [I]); printf ("\ n reachtime:"); scanf ("% d", & reachtime [I]); printf ("\ n needtime: "); scanf (" % d ", & needtime [I]) ;}for (I = 0; I <n; I ++) {for (j = 1; j <n-1-i; j ++) {If (needtime [J]> needtime [J + 1]) {temp = needtime [J + 1]; needtime [J + 1] = needtime [J]; needtime [J] = temp; ctemp = Name [J + 1]; name [J + 1] = Name [J]; name [J] = ctemp; temp = reachtime [J + 1]; reachtime [J + 1] = reachtime [J]; reachtime [J] = temp ;} else if (needtime [J] = needtime [J + 1] & reachtime [J]> reachtime [J + 1]) {temp = needtime [J + 1]; needtime [J + 1] = needtime [J]; needtime [J] = temp; ctemp = Name [J + 1]; name [J + 1] = Name [J]; name [J] = ctemp; temp = reachtime [J + 1]; reachtime [J + 1] = reachtime [J]; reachtime [J] = temp ;}}} for (I = 0; I <n; I ++) {if (I = 0) {starttime [I] = reachtime [I];} finishtime [I] = starttime [I] + needtime [I]; cycletime [I] = finishtime [I]-reachtime [I]; cltime [I] = cycletime [I] * 1.0/needtime [I]; starttime [I + 1] = finishtime [I];} printf ("\ n \ tname reachtime needtime startime finishtime cycletime cltime"); for (I = 0; I <n; I ++) {printf ("\ n \ t % C \ t % d \ t %. 2f ", name [I], reachtime [I], needtime [I], starttime [I], finishtime [I], cycletime [I], cltime [I]) ;}}
Running result:
Experiment 2 Job Scheduling Simulation Program (final)