Write a C program to perform First Come First Serve Algorithm

By | 03.12.2016

C program for First Come First Serve Algorithm


Write a C program to perform First Come First Serve Algorithm. Here you will get C program for first come first served (FCFS) scheduling algorithm.


What is First Come First Serve (FCFS) Algorithm?


First Come First Serve (FCFS) is a Non-Preemptive scheduling algorithm. FIFO (First In First Out) strategy assigns priority to process in the order in which they request the processor.

The process that requests the CPU first is allocated the CPU first. This is easily implemented with a FIFO queue for managing the tasks. As the process come in, they are put at the end of the queue. As the CPU finishes each task, it removes it from the start of the queue and heads on to the next task.


ALGORITHM


  1. Start the process
  1. Declare the array size
  1. Get the number of processes to be inserted
  1. Get the value
  1. Start with the first process from it’s initial position let other process to be in queue
  1. Calculate the total number of burst time
  1. Display the values
  1. Stop the process

Below is the source code for C program to perform First Come First Serve Algorithm which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


#include<stdio.h>
#include<conio.h>
int main()
{
    int n,i,j,sum=0;
    int arrv[10],ser[10],start[10];
    int finish[10],wait[10],turn[10];
    float avgturn=0.0,avgwait=0.0;
    start[0]=0;
    printf("Enter the number of processes:");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter the arriwal and service time of %d process:",i+1);
        scanf("%d%d",&arrv[i],&ser[i]);
    }
    for(i=0;i<n;i++)
    {
        sum=0;
        for(j=0;j<i;j++)
        sum=sum+ser[j];
        start[i]=sum;
    }
    for(i=0;i<n;i++)
    {
        finish[i]=ser[i]+start[i];
        wait[i]=start[i];
        turn[i]=ser[i]+wait[i];
    }
    for(i=0;i<n;i++)
    {
        avgwait+=wait[i];
        avgturn+=turn[i];
    }
    avgwait/=n;
    avgturn/=n;
    printf("\narraival service Start Finish Wait Turn\n");
    for(i=0;i<n;i++)
    printf("%d\t%d\t%d\t%d\t%d\t%d\n",arrv[i],ser[i],start[i],
    finish[i],wait[i],turn[i]);
    printf("\nAverage waiting time=%f",avgwait);
    printf("\nAverage turn around time=%f",avgturn);
    return 0;
}

OUTPUT : :


Enter the number of processes:5
Enter the arriwal and service time of 1 process:3 7
Enter the arriwal and service time of 2 process:7
77
Enter the arriwal and service time of 3 process:2
4
Enter the arriwal and service time of 4 process:4
2
Enter the arriwal and service time of 5 process:
5
4

arraival service Start Finish Wait Turn
3       7       0       7       0       7
7       77      7       84      7       84
2       4       84      88      84      88
4       2       88      90      88      90
5       4       90      94      90      94

Average waiting time=53.799999
Average turn around time=72.599998
0 0 votes
Article Rating
Category: Advance Programs C Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments