Source code SJF Programming Algorithm

#include<stdio.h>

main()

{

int n,j,temp,temp1,temp2,

pr[10],b[10],t[10],w[10],p[10],i;

float att=0;awt=0;

for(i=0;i<10;i++)

{

b[i]=0;w[i]=0;

}

printf(“Enter the number of process:”);

scanf(“%d”,&n);

printf(“\n Enter the burst time”);

for(i=0;i<n;i++)

{

scanf(“%d”,&b[i]);

p[i]=i;

}

for(i=0;i<n;i++)

{

for(j=1;j<n;j++)

{

if(b[i]>b[j]

{

temp=b[i];

temp1=p[i];

b[i]=b[j];

p[i]=p[j];

b[j]=temp;

p[j]=temp1;

}

}

w[0]=0;

for(i=0;i<n;i++)

w[i+1]=w[i]+b[i];

for(i=0;i<n;i++)

{

t[i]=w[i]+b[i];

awt=aw+w[i]:

att=att+t[i];

}

awt=awt/n;

att=att/n;

printf(“\n\t Process \tWaitimgtime \t Turnaroundtime\n);

for(i=0;i<n;i++)

printf(“\t p[%d] \t %d\t\t %d\n”,p[i].w[i],t[i]);

printf(“\n The average waiting time is %t \n”,awt);

printf(“The average turnaround time is %f\n”,att);

return 1;

}

OUTPUT CS1252 Operating Systems lap

[redhat35@localhost Rhel5]$ cc sjf.c

[redhat35@localhost Rhel5]$ ./a.out

Enter the number of process:5

Enter the burst time:5

4

3

2

1

Process Waiting time Turnaround time

P[4] 0 1

P[0] 1 6

P[1] 6 10

P[2] 10 13

P[3] 13 15

The average waiting time is 6.000000

The average turnaround time is 9.000000

#include<stdio.h>

main()

{

int n,j,temp,temp1,temp2,

pr[10],b[10],t[10],w[10],p[10],i;

float att=0;awt=0;

for(i=0;i<10;i++)

{

b[i]=0;w[i]=0;

}

printf(“Enter the number of process:”);

scanf(“%d”,&n);

printf(“\n Enter the burst time”);

for(i=0;i<n;i++)

{

scanf(“%d”,&b[i]);

p[i]=i;

}

for(i=0;i<n;i++)

{

for(j=1;j<n;j++)

{

if(b[i]>b[j]

{

temp=b[i];

temp1=p[i];

b[i]=b[j];

p[i]=p[j];

b[j]=temp;

p[j]=temp1;

}

}

w[0]=0;

for(i=0;i<n;i++)

w[i+1]=w[i]+b[i];

for(i=0;i<n;i++)

{

t[i]=w[i]+b[i];

awt=aw+w[i]:

att=att+t[i];

}

awt=awt/n;

att=att/n;

printf(“\n\t Process \tWaitimgtime \t Turnaroundtime\n);

for(i=0;i<n;i++)

printf(“\t p[%d] \t %d\t\t %d\n”,p[i].w[i],t[i]);

printf(“\n The average waiting time is %t \n”,awt);

printf(“The average turnaround time is %f\n”,att);

return 1;

}

OUTPUT CS1252 Operating Systems lap

[redhat35@localhost Rhel5]$ cc sjf.c

[redhat35@localhost Rhel5]$ ./a.out

Enter the number of process:5

Enter the burst time:5

4

3

2

1

Process Waiting time Turnaround time

P[4] 0 1

P[0] 1 6

P[1] 6 10

P[2] 10 13

P[3] 13 15

The average waiting time is 6.000000

The average turnaround time is 9.000000

## 0 comments:

Post a Comment