Monday, February 1, 2010

ps

#include<iostream.h>




int main()
{
int n,i;
cout<<"enter the no. of process";
cin>>n;
int at[n],bt[n],wt[n],st[n];
for(i=0;i<=n-1;i++)
{
cout<<"process:"<<i+1<<endl;
cout<<"-------------------"<<endl;
cout<<"enter the arrival time:";
cin>>at[i];
cout<<"enter the burst time:";
cin>>bt[i];
}
st[0]=0;
wt[0]=0;
int w=0;
for(i=0;i<=n-1;i++)
{
    w=w+bt[i];
    wt[i]=w-(at[i]+bt[i]);
st[i]=wt[i]+at[i];

}
double avg;
avg=(st[n-1]*1.0)/n;

cout<<"\n\nProcess\tArrival\tbusrt\twaiting\tstart\n";
for(i=0;i<=n-1;i++)
{
cout<<i<<"\t"<<at[i]<<"\t"<<bt[i]<<"\t"<<wt[i]<<"\t"<<st[i]<<"\n";
}
cout<<"\n\nAverage time:"<<avg;
return 0;
}

No comments:

Post a Comment