You are on page 1of 4

Priority Scheduling Algorithm

#include<stdio.h>
struct priority
{
Char p[5];
int burst;
int wt;
int tt;
int pri;
};
Void main()
{
struct priority pro[10];
int i,j,n;
float avgwt=0,avgtt=0;
printf(\n Enter the number of process:);
scanf(%d,&n);
printf(\n Enter the process name burst time and priority:);
for(i=0;i<n;i++)
{
printf(\n Enter the process %d,i+1);
scanf(%s%d,&pro[i].p,&pro[i].burst,&pro[i].pri);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(pro[i].pri >pro[j].pri)
{
temp=pro[i];
pro[i]=pro[j[;
pro[j]=temp;
}
pro[0].wt=0;
for(i=1;i<=n;i++)
{
j=i-1;
pro[i].wt=pro[j].wt+pro[j].burst;
}
for(i=0;i<n;i++)
{
www.Technicalsymposium.com

avgwt=avgwt+pro[i].wt;
}
printf(\n Guant Chart:);
for(i=0;i<n;i++)
{
printf(\n %s ,pro[i].p);
}
printf(\n-----------------------------------------------);
for(i=0;i<n;i++)
{
printf(\n %d,pro[i].wt);
}
for(i=0;i<n;i++)
{
pro[i].tt=pro[i].wt+pro[i].burst;
avgtt=avgtt+pro[i].tt;
}
Printf(\n Process \t Burst time \t Waiting time \t Turn around
time);
for(i=0;i<n;i++)
{
printf(\n %s \t\t%d \t %d \t %s);
}
printf(\n Average waiting time : %d ms,avgwt/n);
printf(\n Average turn around time : %d ms,avgtt/n);
}
Output :
Enter the number of process : 3
Enter the process name and burst time :
Enter for process 1 : p1 3
2
Enter for process 2 : p2 24 1
Enter for process 3 : p3 4
3

www.Technicalsymposium.com

Guant Chart :
----------------------------------------------p1
p2
p3
-----------------------------------------------0
24
27
31
Process

Burst time Waiting time

p1
p2
p3

3
24
4

0
24
27

Average waiting time : 17.000000 ms


Average turn around time : 27.333333 ms

www.Technicalsymposium.com

Turn around time


24
27
31

www.Technicalsymposium.com

You might also like