C program for first come first serve scheduling.

Posted by Mangesh on May 02, 2018

/* first come first serve algorithm for scheduling. */

Description :

The simplest CPU scheduling algorithm is the first come first served scheduling(FCFS) algorithm. The process that requests the CPU first is allocated the CPU first. A queue of waiting processes is maintained in FCFS order. When a process completes, thw next process in the queue is allocated the CPU. The FCFS algorithm is non pre- emptive.

Program :

#include<stdio.h>
#include<conio.h>
void main()
{
 int bursttime[100],responsetime[100],turnaroundtime[100];
 int i,n,totalRT=0,totalTT=0;
 clrscr();
 printf("Enter total number of process : ");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\nEnter the burst time of %d process : ",i+1);
  scanf("%d",&bursttime[i]);
 }
  printf("process number \t\tResponse time\t\t Turnaround time");
 responsetime[0] = 0;
 for(i=0;i<n;i++)
 {
  if(i==0)
   turnaroundtime[i]=bursttime[i];
  else
   turnaroundtime[i]=bursttime[i]+turnaroundtime[i-1];

  printf("\n \t%d \t\t\t %d \t\t\t %d",i+1,responsetime[i],turnaroundtime[i]);
  responsetime[i+1]=turnaroundtime[i];
   totalRT = totalRT + responsetime[i];
   totalTT = totalTT + turnaroundtime[i];
   }
 printf("\nAverage waiting time is %f",(float)totalRT/n);
 printf("\nAverage response time is %f",(float)totalRT/n);
 printf("\nAverage turnaround time is %f ",(float)totalTT/n);
 getch();
}

Output :

c program for first come first serve Executed and tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program for first come first serve scheduling.
2 C program for shortest job first scheduling algorithm.
3 C program for shortest remaining time first scheduling algorithm.
4 C program for round robin scheduling algorithm.
Latest Post
1 shubhanshu
2 test
3 C program for Breadth First Search.
4 C program for Depth First Search(DFS).
5 C for circular queue using linked list.