#include< stdio.h>
#include< conio.h>
void main()
{
int
njob,pID[15],aTime[15],bTime[15],jcTime[15],taTime[15],wTime[15],i,j,temp,sTime[15],prior[15];
float totalWait,totalTA;
clrscr();
printf("\n Enter number of process:");
scanf("%d",&njob);
for(i=0;i< njob;i++)
{
printf("\n Enter the Arrival time , Burst time and Priority for process[%d]:",i+1);
scanf("%d %d %d",&aTime[i],&bTime[i],&prior[i]);
pID[i]=i+1;
}
for(i=0;i< njob;i++)
{
for(j=i+1;j< njob;j++)
{
if(prior[i]>prior[j])
{
temp=pID[i];
pID[i]=pID[j];
pID[j]=temp;
temp=aTime[i];
aTime[i]=aTime[j];
aTime[j]=temp;
temp=bTime[i];
bTime[i]=bTime[j];
bTime[j]=temp;
temp=prior[i];
prior[i]=prior[j];
prior[j]=temp;
}
}
}
for(i=0;i< njob;i++)
{
if(i==0)
{
sTime[0]=aTime[i];
}
else
{
sTime[i]=jcTime[i-1];
}
jcTime[i]=sTime[i]+bTime[i];
taTime[i] = jcTime[i]-aTime[i];
wTime[i] = taTime[i] - bTime[i];
}
printf("\n Process ArrivalTime BurstTime Priority TurnaroundTime WaitingTime");
printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
for(i=0;i< njob;i++)
{
printf("\n %d \t\t %d \t %d \t %d",pID[i],aTime[i],bTime[i],prior[i]);
printf("\t\t %d",taTime[i]);
printf("\t\t %d",wTime[i]);
totalTA=totalTA+taTime[i];
totalWait=totalWait+wTime[i];
}
printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
printf("\n total waiting time:%.2f",totalWait/njob);
printf("\n total turn around time:%.2f",totalTA/njob);
getch();
}
OUTPUT
Enter number of process:5
Enter the Arrival time , Burst time and Priority for process[1]:0 10 3
Enter the Arrival time , Burst time and Priority for process[2]:0 6 5
Enter the Arrival time , Burst time and Priority for process[3]:0 2 2
Enter the Arrival time , Burst time and Priority for process[4]:0 4 1
Enter the Arrival time , Burst time and Priority for process[5]:0 8 4
Process ArrivalTime BurstTime Priority TurnaroundTime WaitingTime
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
4 0 4 1 4 0
3 0 2 2 6 4
1 0 10 3 16 6
5 0 8 4 24 16
2 0 6 5 30 24
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
total waiting time:10.00
total turn around time:16.00
#include< conio.h>
void main()
{
int
njob,pID[15],aTime[15],bTime[15],jcTime[15],taTime[15],wTime[15],i,j,temp,sTime[15],prior[15];
float totalWait,totalTA;
clrscr();
printf("\n Enter number of process:");
scanf("%d",&njob);
for(i=0;i< njob;i++)
{
printf("\n Enter the Arrival time , Burst time and Priority for process[%d]:",i+1);
scanf("%d %d %d",&aTime[i],&bTime[i],&prior[i]);
pID[i]=i+1;
}
for(i=0;i< njob;i++)
{
for(j=i+1;j< njob;j++)
{
if(prior[i]>prior[j])
{
temp=pID[i];
pID[i]=pID[j];
pID[j]=temp;
temp=aTime[i];
aTime[i]=aTime[j];
aTime[j]=temp;
temp=bTime[i];
bTime[i]=bTime[j];
bTime[j]=temp;
temp=prior[i];
prior[i]=prior[j];
prior[j]=temp;
}
}
}
for(i=0;i< njob;i++)
{
if(i==0)
{
sTime[0]=aTime[i];
}
else
{
sTime[i]=jcTime[i-1];
}
jcTime[i]=sTime[i]+bTime[i];
taTime[i] = jcTime[i]-aTime[i];
wTime[i] = taTime[i] - bTime[i];
}
printf("\n Process ArrivalTime BurstTime Priority TurnaroundTime WaitingTime");
printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
for(i=0;i< njob;i++)
{
printf("\n %d \t\t %d \t %d \t %d",pID[i],aTime[i],bTime[i],prior[i]);
printf("\t\t %d",taTime[i]);
printf("\t\t %d",wTime[i]);
totalTA=totalTA+taTime[i];
totalWait=totalWait+wTime[i];
}
printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
printf("\n total waiting time:%.2f",totalWait/njob);
printf("\n total turn around time:%.2f",totalTA/njob);
getch();
}
OUTPUT
Enter number of process:5
Enter the Arrival time , Burst time and Priority for process[1]:0 10 3
Enter the Arrival time , Burst time and Priority for process[2]:0 6 5
Enter the Arrival time , Burst time and Priority for process[3]:0 2 2
Enter the Arrival time , Burst time and Priority for process[4]:0 4 1
Enter the Arrival time , Burst time and Priority for process[5]:0 8 4
Process ArrivalTime BurstTime Priority TurnaroundTime WaitingTime
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
4 0 4 1 4 0
3 0 2 2 6 4
1 0 10 3 16 6
5 0 8 4 24 16
2 0 6 5 30 24
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
total waiting time:10.00
total turn around time:16.00