C program for First Come First Served Scheduling

C program for First Come First Served Scheduling, is always one of the most popular scheduling algorithm used for decades. First Come First Served Scheduling is a Non-Preemptive algorithm.In this scheduling, the process request the CPU First , will get the CPU First.A simple FIFO (First In First Out) Queue is used for implementing scheduling algorithm.When the CPU completes the current process, next process will be automatically selected from the queue.

Jobs are executed on first come, first serve basis.
Easy to implement and understand.
Performance is very low, since waiting time is very high.

C program for First Come First Served Scheduling Program

#include<stdio.h>
main()
{
int n,arrival_time[10],burst_time[10],turn_around_time[10],waiting_time[10],g[10],i,m;
float average_trun_around_time=0,average_waiting_time=0;
            for(i=0;i<10;i++)
            {
                        arrival_time[i]=0; burst_time[i]=0; waiting_time[i]=0; g[i]=0;
            }
printf("enter the number of process");
            scanf("%d",&n);
printf("enter the burst times");
            for(i=0;i<n;i++)
                scanf("%d",&burst_time[i]);
printf("nenter the arrival times");
            for(i=0;i<n;i++)
                scanf("%d",&arrival_time[i]);
    g[0]=0;
             for(i=0;i<10;i++)
                   g[i+1]=g[i]+burst_time[i];
             for(i=0;i<n;i++)
            {
waiting_time[i]=g[i]-arrival_time[i];
                        turn_around_time[i]=g[i+1]-arrival_time[i];
                        average_waiting_time=average_waiting_time+waiting_time[i];
                        average_trun_around_time=average_trun_around_time+turn_around_time[i];
            }
     average_waiting_time =average_waiting_time/n;
            average_trun_around_time=average_trun_around_time/n;
            printf("ntprocesstwaiting timetturn arround timen");
            for(i=0;i<n;i++)
            {
                        printf("tp%dtt%dtt%dn",i,waiting_time[i],turn_around_time[i]);
            }
printf("the average waiting time is %fn",average_waiting_time);
printf("the average turn around time is %fn",average_trun_around_time);
}

So that’s it. C program for First Come First Served Scheduling (or FCFS Scheduling). I hope you understand all the aspects of the program. It is obvious that, you may have doubts. In that case, drop your comments below. Happy programming.