Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
C :: Parsing using strtok 
C :: how to limit tiktok on mikrotik 
C :: overhead computer science 
C :: arma 3 key pressed 
C :: reading arrays from stdin c 
C :: Dynamic Memoray alocation For 2D 
C :: c pointers to struct 
C :: __isoc99_sscanf 
C :: UTC offset upper limit 
C :: reverse binary tree c 
C :: C static libraries creation 
C :: read from text file in c 
C :: WAP to create Database using array of structure & display it in C 
C :: manasa loves maths solution IN C 
C :: c refresher 
C :: reap zombie process in c 
C :: /usr/bin/mandb: fopen /var/cache/man/7935: Permission denied 
C :: QDrag and Drop 
C :: come fare un programma in c con cui interagire 
C :: print binary c 
C :: concate string in c 
C :: array length in c++ 
Dart :: asset image in circle avatar flutter 
Dart :: flutter padding top and bottom 
Dart :: flutter how to space buttons evenly in a row 
Dart :: options != null "FirebaseOptions cannot be null when creating the default app." 
Dart :: how to add padding flutter 
Dart :: how to use hexadecimal color in flutter 
Dart :: flutter reverse list 
Dart :: inheritance in dart 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =