#include<stdio.h>
#include<conio.h>
int main()
{
int temp,temp1,n,pp[10],bt[10],waiting[10],awt=0,i,twt=0,j;
printf("Enter the number of process : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter process burst time");
scanf("%d",&bt[i]);
printf(" : time priorities \n");
scanf("%d",&pp[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pp[i]>pp[j])
{
temp=pp[i];
pp[i]=pp[j];
pp[j]=temp;
temp1=bt[i];
bt[i]=bt[j];
bt[j]=temp1;
}
}
}
waiting[0]=0;
for(i=1;i<n;i++)
{
waiting[i]=waiting[i-1]+bt[i-1];
twt=twt+waiting[i];
}
printf("\ntotal waiting time=%d",twt);
awt=twt/n;
printf("\nAverage waiting time=%d",awt);
getch();
}
#include<conio.h>
int main()
{
int temp,temp1,n,pp[10],bt[10],waiting[10],awt=0,i,twt=0,j;
printf("Enter the number of process : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter process burst time");
scanf("%d",&bt[i]);
printf(" : time priorities \n");
scanf("%d",&pp[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pp[i]>pp[j])
{
temp=pp[i];
pp[i]=pp[j];
pp[j]=temp;
temp1=bt[i];
bt[i]=bt[j];
bt[j]=temp1;
}
}
}
waiting[0]=0;
for(i=1;i<n;i++)
{
waiting[i]=waiting[i-1]+bt[i-1];
twt=twt+waiting[i];
}
printf("\ntotal waiting time=%d",twt);
awt=twt/n;
printf("\nAverage waiting time=%d",awt);
getch();
}
No comments:
Post a Comment