Simulate the following CPU scheduling algorithms FCFS
#include<stdio.h>
#include<conio.h>void main()
{
int n,i,bt[10],wt[10],tt[10],totalwt=0,totaltt=tt[0];
float avgwt,avgtt;
clrscr();
printf("\nEnter No.of Processers:");
scanf("%d",&n);
printf("\nEnter Elements into Burst Time:");
for (i=0;i<n;i++){
scanf("%d",&bt[i]);
}
wt[0]=0;
tt[0]=bt[0];
for(i=1;i<n;i++)
{ // wt[0]=0;
// tt[0]=bt[0];
wt[i]=wt[i-1]+bt[i-1];
tt[i]=wt[i]+bt[i];
totaltt+=tt[i];
totalwt+=wt[i];
}
printf("BT\t\tWT\t\tTT\n");
for(i=0;i<n;i++){
printf("%d\t\t%d\t\t%d\n",bt[i],wt[i],tt[i]);
}
avgtt=totaltt/n;
avgwt=totalwt/n;
printf("\nAverage Waiting Time is %f\n",avgwt);
printf("\nAverage Turnaround Time is %f\n",avgtt);
getch();
}
Comments
Post a Comment