JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
5 months ago74 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;
}

⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.

← Back to timeline