Program for First In First Serve Algorithm
=========================================================
#include
#include
#include
void main()
{
int n,b[10],w[10],i,j,h;
int stime[10];
float avg=0;
clrscr();
printf("\n\tJOB SCHEDULING ALGORITHM[FCFS]");
printf("\n\t*************************************************
****\n");
printf("\nEnter howmany jobs:");
scanf("%d",&n);
printf("\nEnter burst time for corresponding job....\n");
for(i=0;i
{
printf("\nProcess %d:",i+1);
scanf("%d",&b[i]);
}
w[0]=0;
printf("\nprocess 1 waiting time is 0");
for(i=1;i
{
w[i]=b[i-1]+w[i-1];
printf("\nProcess %d waiting time: %d",i+1,w[i]);
avg+=w[i];
}
printf("\ntotal waiting time:%f",avg);
printf("\n\nthe average waiting time is:%f\n",avg/n);
printf("\nGaunt
Chart\n***************************************\n\n\t");
h=22;
for(i=0;i
{
printf("%d",b[i]);
for(j=1;j<=b[i];j++)
printf("%c",h);
}
printf("\n\t");
for(i=0;i
{
printf("%d",w[i]);
for(j=1;j<=w[i];j++)
printf("%c",h);
delay(1000);
}
getch();
}
========================================================
=========================================================
#include
#include
#include
void main()
{
int n,b[10],w[10],i,j,h;
int stime[10];
float avg=0;
clrscr();
printf("\n\tJOB SCHEDULING ALGORITHM[FCFS]");
printf("\n\t*************************************************
****\n");
printf("\nEnter howmany jobs:");
scanf("%d",&n);
printf("\nEnter burst time for corresponding job....\n");
for(i=0;i
{
printf("\nProcess %d:",i+1);
scanf("%d",&b[i]);
}
w[0]=0;
printf("\nprocess 1 waiting time is 0");
for(i=1;i
{
w[i]=b[i-1]+w[i-1];
printf("\nProcess %d waiting time: %d",i+1,w[i]);
avg+=w[i];
}
printf("\ntotal waiting time:%f",avg);
printf("\n\nthe average waiting time is:%f\n",avg/n);
printf("\nGaunt
Chart\n***************************************\n\n\t");
h=22;
for(i=0;i
{
printf("%d",b[i]);
for(j=1;j<=b[i];j++)
printf("%c",h);
}
printf("\n\t");
for(i=0;i
{
printf("%d",w[i]);
for(j=1;j<=w[i];j++)
printf("%c",h);
delay(1000);
}
getch();
}
========================================================
SAMPLE INPUT AND OUTPUT:
Enter howmany jobs:5
Enter howmany jobs:5
Enter burst time for corresponding job....
Process 1:4
Process 2:2
Process 3:8
Process 4:2
Process 5:9
process 1 waiting time is 0
Process 2 waiting time: 4
Process 3 waiting time: 6
Process 4 waiting time: 14
Process 5 waiting time: 16
total waiting time:40.000000
Process 2 waiting time: 4
Process 3 waiting time: 6
Process 4 waiting time: 14
Process 5 waiting time: 16
total waiting time:40.000000
the average waiting time is:8.000000
Gaunt Chart
***************************************
***************************************
4▬▬▬▬2▬▬8▬▬▬▬▬▬▬▬2▬▬9▬▬▬▬▬▬▬▬▬
04▬▬▬▬6▬▬▬▬▬▬14▬▬▬▬▬▬▬▬▬▬▬▬▬▬16▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
04▬▬▬▬6▬▬▬▬▬▬14▬▬▬▬▬▬▬▬▬▬▬▬▬▬16▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
No comments:
Post a Comment