#include<stdio.h>
#include<conio.h>
#define max 10
int i,nop;
struct process
{
int prn;
int bt;
int wt;
int tt;
}pr[max];
void ins_dat()
{
for(i=0;i<nop;i++)
{
pr[i].prn = i+1;
printf("\n Enter the Burst time of Process #%d : ",pr[i].prn);
scanf("%d",&pr[i].bt);
}
}
void FCFS()
{
for(i=0;i<nop;i++)
{
pr[i].wt = pr[i].prn == 1 ? 0 : pr[i-1].tt ;
pr[i].tt = pr[i].wt + pr[i].bt;
}
}
void disp_dat()
{
int ttl_tt=0,ttl_wt=0;
float avg_tt,avg_wt;
printf("\n\n Process Waiting Time Burst Time Turnaround Time \n");
printf(" ------------------------------------------------------- \n");
for(i=0;i<nop;i++)
{
printf(" %d \t\t %d \t\t %d \t\t %d\n\n",pr[i].prn,pr[i].wt,pr[i].bt,pr[i].tt);
ttl_wt += pr[i].wt;
ttl_tt += pr[i].tt;
}
avg_wt = (float) ttl_wt/nop;
avg_tt = (float) ttl_tt/nop;
printf("\n\n Average Waiting Time : %f",avg_wt);
printf("\n Average Turnaround Time : %f",avg_tt);
}
void main()
{
do
{
printf("\n Enter the number of processes : ");
scanf("%d",&nop);
}while(nop > max || nop <= 0);
ins_dat();
FCFS();
disp_dat();
getch();
}
No comments:
Post a Comment