#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n, process[10],total=0, wtime[10],ptime[10],temp,
ptemp;float avg=0;
printf("\n Enter number of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter process %d 1d : ",i+1);
scanf("%d",&process[i]);
printf("\n Enter process %d Time: ",i+1);
scanf("%d",&ptime[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(ptime[i]=ptime[j])
{
temp=ptime[i];
ptime[i]=ptime[j];
ptime[j]=temp;
ptemp=process[i];
process[i]=process[j];
process[j]=ptemp;
}
}
}
wtime[0]=0;
for(i=1;i<n;i++)
{
wtime[i]=wtime[i-1]+ptime[i-1];
total=total+wtime[i];
}
avg=(float)total/n;
printf("\np_ID\t p_Time\t w-TIME\n");
for(i=0;i<n;i++)
printf("%d\t%d\t%d\n",process[i],ptime[i],wtime[i]);
printf("\nTotal waiting time : %d \nAverage waiting time:%f",total,avg);
getch();
}