#include <stdio.h>#defineN 5structjcb{intName//Process Name intAtime//Process Arrival Time intRuntime//Process Run Time intFtime;//Process Finish Time intTotal//Turnaround Time floatWelght;//weighted turnaround time (turnover factor) intArun//Process arrives Run}f[n];//start execution time, time of completion of each job, turnaround time and time of ownership turnaround (turnover factor). voidMain () {intamount; inti,j,l,k,h; structJCB F[n]; printf ("Please enter the number of processes (2-24): \ n"); scanf ("%d",&amount); for(i=0; i<amount;i++) {printf ("Please enter the process name, process arrival time (0-30), Process run time (1-8): \ n"); scanf ("%d",&f[i].name); scanf ("%d",&f[i].atime); scanf ("%d",&f[i].runtime); } printf ("process name \ t process arrival time \ t process run time \ n"); for(i=0; i<amount;i++) {printf ("%d\t%d\t\t%d\t\n", F[i].name,f[i].atime,f[i].runtime); } printf ("------First-come-first service (FCFS) scheduling algorithm------\ n"); for(i=0; i<amount-1; i++)//sequencing by process arrival time{//If two processes arrive at the same time, press ENTER first on the screen to run for(j=i+1; j<amount;j++) { if(F[j].atime <f[i].atime) {L=F[j].atime; H=F[j].runtime; K=F[j].name; F[j].atime=F[i].atime; F[j].runtime=F[i].runtime; F[j].name=F[i].name; F[i].atime=M; F[i].runtime=h; F[i].name=K; }}} printf ("Order of arrival time by process \ n"); printf ("process name \ t process arrival time \ t process run time \ n"); for(i=0; i<amount;i++) {printf ("%d\t%d\t\t%d\t\n", F[i].name,f[i].atime,f[i].runtime); } printf ("Process name process reaches start run process run process end turnaround factor \ n"); f[0].arun=0; for(i=0; i<amount;i++) { if(f[i].arun<f[i].atime) {F[i].arun=F[i].atime; } f[i].ftime=f[i].arun+F[i].runtime; F[i].total=f[i].ftime-F[i].atime; F[i].welght=(float) f[i].total/(float) F[i].runtime; printf ("%d\t%d\t%d\t%d\t%d\t\t%d\t%f\n", F[i].name,f[i].atime,f[i].arun,f[i].runtime,f[i].ftime,f[i].total,f[i].welght); F[i+1].arun=f[i].arun+F[i].ftime; }}
First come first service (FCFS) scheduling algorithm