0% found this document useful (0 votes)
28 views2 pages

SJF

sjf

Uploaded by

divyanshra75
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

SJF

sjf

Uploaded by

divyanshra75
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>

void main()
{
int bt[20], p[20], wt[20], tat[20], pr[20], i, j, n, total=0, pos, temp;
float avg_wt, avg_tat;

printf("Enter Number of Process:");


scanf("%d", &n);

printf("\nEnter Burst Time and Priority\n");


for(i=0; i<n; i++)
{
printf("\nP[%d]\n", i+1);
printf("Burst Time:");
scanf("%d", &bt[i]);
printf("Priority:");
scanf("%d", &pr[i]);
p[i]=i+1; //contains process number
}

//sorting burst time in ascending order using selection sort


for(i=0; i<n-1; i++)
{
pos=i;
for(j=i+1; j<n; j++)
{
if(pr[j]<pr[pos])
pos=j;
}

temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

//calculate waiting time


wt[0]=0;
for(i=1; i<n; i++)
{
wt[i]=0;
for(j=0; j<i; j++)
wt[i]+=bt[j];
total+=wt[i];
}

avg_wt=(float)total/n;

total=0;
printf("\nProcess\t Burst Time\t Waiting Time\tTurnaround Time");
for(i=0; i<n; i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\nP[%d]\t\t %d\t\t %d\t\t\t%d", p[i], bt[i], wt[i], tat[i]);
}

avg_tat=(float)total/n;
printf("\n\nAverage Waiting Time=%f", avg_wt);
printf("\nAverage Turnaround Time=%f\n", avg_tat);
}

You might also like