Thursday , September 21 2017
Home / C / Program for Shortest Job First (SJF) scheduling technique

Program for Shortest Job First (SJF) scheduling technique

SJF scheduling: c program for sjf in c.

#include <stdio.h>
#include <conio.h>
#include "stdlib.h"
void sjpseq(int p[],int bt[],int n)
{
int temp,i,j,pos;
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{

if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
}

int main()
{
    int p[20],bt[20],wait[20],tnt[20],i,n;
    float wt=0,trn=0;

    printf("Enter total number of process ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter Burst Time of %d process ",i+1);
        scanf("%d",&bt[i]);
        p[i]=i+1;
    }
sjpseq(p,bt,n);
wait[0]=0;
printf("\nRearranged pes according to Shortest Job First are\n\n");
for(i=0;i<n;i++)
{
wait[i+1]=wait[i]+bt[i];
tnt[i]=wait[i]+bt[i];
wt+=wait[i];
trn+=tnt[i];
printf("\nProcess %d  Burst Time TIME %d  WAIT TIME %d  tntAROUND TIME %d",p[i],bt[i],wait[i],tnt[i]);
}
wt/=n;
trn/=n;
printf("\n\nAverage Wait Time is %f",wt);
printf("\nAverage tntaround Time is %f",trn);
return 1;
}

OUTPUT:

Program for shortest job first scheduling algorithm
 
 
Tags: program for SJF scheduling in c, SJF program in c, program for sjf in c, SJF scheduling in c.
 

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

Leave a Reply

Your email address will not be published. Required fields are marked *