Home » NO IDEA » shortest job first

shortest job first

Blog Stats

  • 13,912 hits
April 2013
M T W T F S S
« Mar   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

#include<stdio.h>

#include<stdlib.h>
struct process
{
int pid;
int wt,tt,bt;
}
p[100];
int main()
{
struct process temp;
int tottt,totwt,avgtt,avgwt,i,j,n;

printf("\nEnter Number of process");
scanf("\n%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf("\nEnter %d Burst Time:",i);
scanf("\n%d",&p[i].bt);
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[i].bt>p[j].bt)
{

temp=p[j];
p[j]=p[i];
p[i]=temp;
}}}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].tt;
p[i].tt=p[i].bt+p[i].wt;
i++;
}
totwt=tottt=0;
i=1;
printf("\n\t=================================");
printf("\n\t Process id \tBT\tWT\tTT");
printf("\n\t================================");
while(i<=n)
{
printf("\n\t%d\t%d\t%d\t%d\t",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
}
totwt=totwt/n;

tottt=tottt/n;
printf("\n\n\n\tAVGWT\tAVGTT");
printf("\n\t%d\t%d",totwt,tottt);
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: