C Program to implement FCFS algorithm.

Write a C Program to implement FCFS algorithm.
First Come First Served(FCFS) algorithm is the CPU scheduling algorithm. In FCFS process is served when they are arrived in order, i.e First In First Out(FIFO). FCFS is the simple scheduling algorithm, but it takes typically long/varying waiting time.
Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
#include<stdio.h>
#include<conio.h>
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;
clrscr();
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 Turnn");
for(i=0;i<n;i++)
printf("%dt%dt%dt%dt%dt%dn",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);
getch();
}
Read more Similar C Programs
C Basic

Search Algorithms.

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com