Skip to main content
JustPaste
HomeAboutDonateContactTerms of UsePrivacy Policy

© 2026 Just Paste. All rights reserved.

Made with ❤️ by TakiDev

Untitled Page | JustPaste.app
Publish about 1 month ago53 views

#include<stdio.h>

int main()

{

int pid[20] , bt[20] , wt[20] , tat[20];

int n , i , j , temp;

float total = 0 , totalT = 0 ;

printf("Enter number of processes (<=20): ");

scanf("%d",&n);

printf("Enter process id and burst time for each process : \n");

for(i=0;i<n;i++){

printf("Process %d id : ", i + 1 );

scanf("%d",&pid[i]);

printf("Burst time for P%d: ", pid[i]);

scanf("%d",&bt[i]);

}

for(i=1;i<n-1;i++){

for(j=0;j<n-i-1;j++){

if(bt[j] > bt[j + 1]){

temp = bt[j];

bt[j] = bt[j+1];

bt[j+1] = temp;

temp = pid[j];

pid[j] = pid[j + 1];

pid[j + 1] = temp;

}

}

}

wt[0] = 0 ;

for(i=1;i<n;i++){

wt[i] = 0 ;

for(j = 0 ; j < i ; j++){

wt[i] += bt[j];

}

}

for(i=0;i < n ; i++){

tat[i] = bt[i] + wt[i];

total += wt[i];

totalT += tat[i];

}

printf("\nSJF Scheduling : \n");

printf("PID\tBT\tWT\tTAT\n");

for(i = 0 ; i < n ; i++) {

printf("%d\t%d\t%d\t%d\n" , pid[i] , bt[i] , wt[i] , tat[i]);

}

printf("\nAverage Waiting Time = %.2f\n" , total / n);

printf("Average Turnaround Time = %.2f\n" , totalT / n);

return 0;

}