PRIORITY ALGORITHM
#include<stdio.h>
main()
{
int a[20],b[20],c[20],i,j,n,bt=0;
clrscr();
printf("\nEnter no of jobs");
scanf("%d",&n);
printf("Enter priority of process");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Enter burst time");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
for(i=1;i<=n;i++)
c[i]=i;
for(i=1;i<=n;i++)
for(j=i;j<=n;j++)
if(a[i]>a[j])
{
a[i]=((a[i]+a[j])-(a[j]=a[i]));
b[i]=((b[i]+b[j])-(b[j]=b[i]));
c[i]=((c[i]+c[j])-(c[j]=c[i]));
}
printf("the process sequence is\n");
for(i=1;i<=n;i++)
printf("p%d\t",c[i]);
printf("\n");
printf("\nburst time\n");
for(i=1;i<=n;i++)
printf("%d\t",b[i]);
for(i=1;i<=n;i++)
{
bt=bt+b[i];
}
printf("\n\nTotal burst time=%d",bt);
}
No comments:
Post a Comment