Write a program to implement first come first serve algorithm (FCFS) without considering arrival time

  The following c program will help you to implemen first come first serve algorithm (FCFS) without considering arrival time

Calculating Average Waiting Time and Turn-Around Time using Ghantt Chart:

Gantt Chart:

 
__________________________
| P1 | P2 | P3 | P4 | P5 |
|____|____|____|____|____|
0    2    7   15   19    25

Process  	TAT     WT  

P1  	     2      0 
P2           7       2
P3           15      7
P4           19      15
P5           25      19

Average Waiting Time : 8.000000 
Average Turn-Around Time : 13.000000

Table of Contents

C Program Code

   
 

/*;==========================================
; Title: Write a program to implement first come first serve algorithm (FCFS) without considering arrival time. 
; Owned: codenaive littleboy8506@  <admin@codenaive.com> <s.8506.a@gmail.com>
; Contribution:  Mansi bansal
; Programming Language: C
; Date:   1 Feb 2021
;==========================================*/
#include<stdio.h>
int Gantt(int P[5],int sum[6])
{
int i;
float avgWT=0.0,avgTAT=0.0;
printf("Gantt Chart:\n");
printf("_______________________________\n");
for(i=0;i<5;i++)
{
printf("| P%d  ",P[i]);
}
printf("|\n|_____|_____|_____|_____|_____|\n");
printf("0     %d     %d     %d    %d     %d",sum[1],sum[2],sum[3],sum[4],sum[5]);
printf("\n\n");
printf("Process\t\tTAT\tWT");
for(i=0;i<5;i++)
{
printf("\nP%d\t\t%d\t%d",i+1,sum[i+1],sum[i]);
}
avgWT=(sum[0]+sum[1]+sum[2]+sum[3]+sum[4])/5;
avgTAT=(sum[1]+sum[2]+sum[3]+sum[4]+sum[5])/5;
printf("\nAverage Waiting Time : %f",avgWT);
printf("\nAverage Turn-Around Time : %f",avgTAT);
printf("\n");
}
int main()
{
int i,j,BT[5],AT[5],TAT[5],WT[5],c=0,sum[6],P2[5],BT2[5],avgWT=0,avgTAT=0,idle,n=5;
sum[0]=0;
int P[5],k=0,sno=1,a=1;
do{
printf("Case %d:\n",a);
a++;
printf("%d ",sno);
printf("Enter new Process order : ");
sno++;
for(i=0;i<5;i++)
{
scanf("%d",&P[i]);
}
printf("\nEnter Burst time order wise : ");
for(i=0;i<5;i++)
{
scanf("%d",&BT[i]);
}
for(i=0;i<5;i++)
{
    c=c+BT[i];
    sum[i+1]=c;
}
Gantt(P,sum);
c=0;
k++;
}while(k<5);
}



			 
						 
			 
						 					

Output

~/admin@codenaive/os $ gcc fcn.c -o fcn
~/admin@codenaive/os $ ./fcn 
Case 1: 
1 Enter new Process order : 1 2 3 4 5 

Enter Burst time order wise : 2 5 8 4 6 
Gantt Chart: 
__________________________
| P1 | P2 | P3 | P4 | P5 |
|____|____|____|____|____|
0    2    7   15   19    25

Process  	TAT     WT  
P1  		 2       0 
P2           7       2
P3           15      7
P4           19      15
P5           25      19

Average Waiting Time : 8.000000 
Average Turn-Around Time : 13.000000

Case 2: 
2 Enter new Process order : 2 1 4 3 5 

Enter Burst time order wise : 5 2 4 8 6
Gantt Chart: 
__________________________
| P1 | P2 | P3 | P4 | P5 |
|____|____|____|____|____|
0    5    7    11   19    25

Process  	TAT     WT  
P1  		 5       0 
P2           7       5
P3           11      7
P4           19      11
P5           25      19

Average Waiting Time : 8.000000 
Average Turn-Around Time : 13.000000

Case 3: 
3 Enter new Process order : 2 4 1 5 3

Enter Burst time order wise : 5 4 2 6 8
Gantt Chart: 
__________________________
| P1 | P2 | P3 | P4 | P5 |
|____|____|____|____|____|
0    5    9    11   17    25

Process  	TAT     WT  
P1  		 5       0 
P2           9       5
P3           11      9
P4           17      11
P5           25      17

Average Waiting Time : 8.000000 
Average Turn-Around Time : 13.000000

Case 4: 
4 Enter new Process order : 1 5 4 3 2

Enter Burst time order wise : 2 6 4 8 5 
Gantt Chart: 
__________________________
| P1 | P2 | P3 | P4 | P5 |
|____|____|____|____|____|
0    2    8    12   20    25

Process  	TAT     WT  
P1  		 2       0 
P2           8       2
P3           12      8
P4           20      12
P5           25      20

Average Waiting Time : 8.000000 
Average Turn-Around Time : 13.000000

Case 5: 
5 Enter new Process order : 3 5 1 4 2

Enter Burst time order wise : 8 6 2 4 5  
Gantt Chart: 
__________________________
| P1 | P2 | P3 | P4 | P5 |
|____|____|____|____|____|
0    8    14    16   20    25

Process  	TAT     WT  
P1  		 8       0 
P2           14      8
P3           16      14
P4           20      16
P5           25      20

Average Waiting Time : 11.000000 
Average Turn-Around Time : 16.000000

						

Leave a Reply

Your email address will not be published. Required fields are marked *