Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Thursday, 16 November 2017

FCFS Scheduling

     C program to implement First come First serve Scheduling


#include<stdio.h>
#include<conio.h>
void main()
{
int a[100][5],n,i,j,k,l;
clrscr();
printf("enter no of processes");
scanf("%d",&n);
printf("enter process details\nprocess no.,arrival time and burst time\n");
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j][1]>a[j+1][1])
for(k=0;k<3;k++)
a[j][k]^=a[j+1][k]^=a[j][k]^=a[j+1][k];
}
}
 k=0,l=a[0][2];
 for(i=0;i<n;i++)
 {
a[i][4]=a[i][3]+a[i][2];
a[i+1][3]=l-a[i+1][1];
printf(" process %d executes from %d to %d\n",a[i][0],k,l);
k=l;
l=l+a[i+1][2];
}
printf("\nPROCESS TABLE:-\n");
printf("PID\tAT\tBT\tWT\tAT\t\n");
for(i=0;i<n;i++)
printf("%d\t%d\t%d\t%d\t%d\n",a[i][0],a[i][1],a[i][2],a[i][3],a[i][4]);
getch();
}


No comments:

Post a Comment