Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

First Come First Serve

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int bt[10] = {0}, at[10] = {0}, tat[10] = {0}, wt[10] = {0}, ct[10] = {0};
	int n, sum = 0;
	int totaltat = 0, totalwt = 0;
	system("clear");
	printf("Enter the number of the process : ");
	scanf("%d",&n);
	printf("Enter the arrival time and bust time :

");
	for( int i = 0; i < n; ++i)
	{
		printf("Enter the arrival time %d : ", i+1 );
		scanf("%d",&at[i]);
		printf("Enter the burst time %d : ", i+1 );
		scanf("%d",&bt[i]);
		printf("
");
	}
	for( int j = 0; j < n; ++j )
	{
		sum += bt[j];
		ct[j] += sum;
	}
	for( int i = 0; i < n; ++i )
	{
		tat[i] = ct[i]-at[i];
		totaltat += tat[i];
	} 
	for( int k = 0; k < n; ++k )
	{
		wt[k] = tat[k]-bt[k];
		totalwt = wt[k];
	}
	printf("solutions :
");
	printf("P	AT	BT	CT	TAT	WT	 

");
	for( int i = 0; i < n; ++i )
	{ 
		printf("%d	%d	%d	%d	%d	%d
",i+1,at[i],bt[i],ct[i],tat[i],wt[i]);
	}
	printf("Average TAT time : %.2f
", totaltat/(float)n);
	printf("Average waiting time : %.2f
",totalwt/(float)n); 
	return 0;
}

// OUTPUT:
// Enter the number of the process : 6
// Enter the arrival time and bust time :
//
// Enter the arrival time 1 : 0
// Enter the burst time 1 : 3
//
// Enter the arrival time 2 : 1
// Enter the burst time 2 : 2
//
// Enter the arrival time 3 : 2
// Enter the burst time 3 : 1
//
// Enter the arrival time 4 : 3
// Enter the burst time 4 : 4
//
// Enter the arrival time 5 : 4
// Enter the burst time 5 : 5
//
// Enter the arrival time 6 : 5
// Enter the burst time 6 : 2
//
// solutions :
//	P	AT	BT	CT	TAT	WT	 
//
//	1	0	3	3	3	0
//	2	1	2	5	4	2
//	3	2	1	6	4	3
//	4	3	4	10	7	3
//	5	4	5	15	11	6
//	6	5	2	17	12	10
// Average TAT time : 6.83
// Average waiting time : 1.67
Source by github.com #
 
PREVIOUS NEXT
Tagged: #First #Come #First #Serve
ADD COMMENT
Topic
Name
7+4 =