#include<iostream.h>
#include<conio.h>
void main()
{
int i, n, process[10], total=0, wtime[10], ptime[10],turntotal[10];
float avg=0;
clrscr();
cout<<"\nEnter number of Processes:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter Process "<<i+1<<" ID:";
cin>>process[i];
cout<<"Enter Process "<<i+1<<" Burst Time:";
cin>>ptime[i];
}
wtime[0]=0;
for(i=1;i<n;i++)
{
wtime[i]=wtime[i-1]+ptime[i-1];
total=total+wtime[i];
}
for(i=0;i<n;i++)
{
turntotal[i]=ptime[i]+wtime[i];
}
avg=(float)total/n;
cout<<"\nP_ID\t P_TIME\t W_TIME\t TURN_Time\n";
for(i=0;i<n;i++)
cout<<process[i]<<"\t"<<ptime[i]<<"\t"<<wtime[i]<<"\t"<<turntotal[i]<<"\n";
cout<<"\nTotal Waiting Time:"<<total;
cout<<"\nAverage Waiting Time:"<<avg;
getch();
}
#include<conio.h>
void main()
{
int i, n, process[10], total=0, wtime[10], ptime[10],turntotal[10];
float avg=0;
clrscr();
cout<<"\nEnter number of Processes:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter Process "<<i+1<<" ID:";
cin>>process[i];
cout<<"Enter Process "<<i+1<<" Burst Time:";
cin>>ptime[i];
}
wtime[0]=0;
for(i=1;i<n;i++)
{
wtime[i]=wtime[i-1]+ptime[i-1];
total=total+wtime[i];
}
for(i=0;i<n;i++)
{
turntotal[i]=ptime[i]+wtime[i];
}
avg=(float)total/n;
cout<<"\nP_ID\t P_TIME\t W_TIME\t TURN_Time\n";
for(i=0;i<n;i++)
cout<<process[i]<<"\t"<<ptime[i]<<"\t"<<wtime[i]<<"\t"<<turntotal[i]<<"\n";
cout<<"\nTotal Waiting Time:"<<total;
cout<<"\nAverage Waiting Time:"<<avg;
getch();
}
No comments:
Post a Comment