FCFS Scheduling


#include<stdio.h>
#include<string.h> //untuk mengaktifkan fungsi strcpy
#include<conio.h>

int burst[5],arrival[5],wait[5];
int n,i,menunggu,turn;
char proses[5][5],temp3[5][5];
float averagewait,averageturn;
void input()
{
puts(“\t\t+++++++++++++++++++++++++++++++++++++++++++++++++++++++”);
puts(“\t\t\tIis Rohmatin Ardila”);
puts(“\t\t\t\t 7411030011”);
puts(“\n\t\t\t=+=+=+=+= PROGRAM FCFS SECHEDULLING =+=+=+=+=”);
printf(“Masukkan banyak proses (p):”);
scanf(“%d”,&n);
puts(“++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++”);

for(i=1;i<=n;i++)
{
printf(“Input nama proses  : “);   //input proses
scanf(“%s”,&proses[i]);

printf(“Input burst time proses %s : “,proses[i]);
scanf(“%d”,&burst[i]);

printf(“Input arrival time %s : “,proses[i]);
scanf(“%d”,&arrival[i]);
}
}

void menungguTime()
{
int i;
wait[1]=0;
for(i=2;i<=n;i++)
{
wait[i]=burst[i-1]+wait[i-1]; //mengurutkan proses wait yang akan ditampilkan dala gambar chart
}
for(i=1;i<=n;i++)
{
menunggu=menunggu+wait[i]-arrival[i]; //proses menghitung waiting proses
turn=turn+(wait[i]+burst[i])-arrival[i];//proses menghitung turn around
}
averagewait=(float)menunggu/n; //menghitung rata-rata waiting process
averageturn=(float)turn/n;    //menghitung rata-rata turn around

printf(“Avverage menunggu time : %f”,averagewait);
printf(“\nAverage turn arround = %f”,averageturn);
}

void gantChart()
{
int i;
printf(“\n\n\t\t=+=+=+=+=+=+=+=+=+= Gambar Chart =+=+=+=+=+=+=+=+=+=+=\n”);
for(i=1;i<=n;i++)
printf(“|\t%s\t”,proses[i]);
printf(“|\t\n”);
printf(“\n—————————————————————————-\n”);
printf(“\n”);
for(i=1;i<=n;i++)
printf(“%d\t\t”,wait[i]);
printf(“%d”,wait[n]+burst[n]);
printf(“\n—————————————————————————-\n”);
printf(“\n”);
}

void tukar()
{
int temp,temp2,temp3[20][20],j;
averagewait=0;
averageturn=0;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++){
if(arrival[i]>arrival[j])
{
temp=burst[i]; //temp untuk menukar nilai burst antar proses
temp2=arrival[i]; //temp2 untuk menukar nilai arrivalnya
burst[i]=burst[j];
arrival[i]=arrival[j];
burst[j]=temp;
arrival[j]=temp2;

strcpy(temp3[i],proses[i]); //untuk menukar nama dari antar proses
strcpy(proses[i],proses[j]);
strcpy(proses[j],temp3[i]);
}
}
}
menungguTime();
gantChart();
}

main()
{
input();
tukar();
}

output:

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s