Where should I insert the arrival time and the burst time in the calculation? In this program, the arrival time,burst time and priority must be enter by the user.and the Average waiting time and average turnaround time must be display at the end of the program.please help
Code:
#include<stdio.h>
int i,j,n;
float totwt;
struct pr
{
char name[5];
int arrival,burst;
int priority;
float twait;
float trnd;
};
struct pr temp;
struct pr pr1[20];
void init()
{
printf("\nEnter the number of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the details of process %d:\n1.Name: ",i+1);
scanf("%s",pr1[i].name);
printf("2.Arrival time: ");
scanf("%d",&pr1[i].arrival);
printf("3.Burst Time: ");
scanf("%d",&pr1[i].burst);
printf("4.Priority: ");
scanf("%d",&pr1[i].priority);
}
}
void prioritysort()
{
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
{
if(pr1[j].priority>pr1[j+1].priority)
{
temp=pr1[j];
pr1[j]=pr1[j+1];
pr1[j+1]=temp;
}
}
}
void calculation()
{
pr1[0].twait=0;
totwt=0;
totserv=pr1[0].trnd=pr1[0].tservice;
for(i=1;i<n;i++)
{
//printf("\nwait= %f",totwt);
pr1[i].twait=pr1[i-1].twait+pr1[i-1].tservice;
totwt+=pr1[i].twait;
pr1[i].trnd=pr1[i].twait+pr1[i].tservice;
totserv+=pr1[i].trnd;
}
}
void printing()
{
printf("Name \tPriority \tArrival Time \tBurst Time \tWaitTime \tTurnAroundTime\n");
for(i=0;i<n;i++)
{
printf("%s \t %d \t\t &d \t%d \t %f \t %f\n",pr1[i].name,pr1[i].priority,pr1[i].arrival,pr1[i].burst,pr1[i].twait,pr1[i].trnd);
}
printf("\nAverage wait:%f \tAverage turnaround:%f \n",totwt/n,totserv/n);
}