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

Doey | JustPaste.app
11 days ago5 views
👨‍💻Programming

Doey

#include <stdio.h>

int main()
{
    int n, i, j;
    int bt[20], p[20];
    int temp;

    printf("Enter number of processes: ");
    scanf("%d", &n);

    // Input burst time
    for(i = 0; i < n; i++)
    {
        p[i] = i + 1;

        printf("Enter Burst Time of P%d: ", p[i]);
        scanf("%d", &bt[i]);
    }

    // Sort processes according to burst time
    for(i = 0; i < n - 1; i++)
    {
        for(j = i + 1; j < n; j++)
        {
            if(bt[i] > bt[j])
            {
                // Swap burst time
                temp = bt[i];
                bt[i] = bt[j];
                bt[j] = temp;

                // Swap process number
                temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }

    int ct[20], wt[20], tat[20];

    // Calculate Completion Time
    ct[0] = bt[0];

    for(i = 1; i < n; i++)
    {
        ct[i] = ct[i - 1] + bt[i];
    }

    // Calculate TAT and WT
    float avg_wt = 0, avg_tat = 0;

    for(i = 0; i < n; i++)
    {
        tat[i] = ct[i];
        wt[i] = tat[i] - bt[i];

        avg_wt = avg_wt + wt[i];
        avg_tat = avg_tat + tat[i];
    }

    // Display result
    printf("\nProcess\tBT\tCT\tTAT\tWT\n");

    for(i = 0; i < n; i++)
    {
        printf("P%d\t%d\t%d\t%d\t%d\n",
               p[i], bt[i], ct[i], tat[i], wt[i]);
    }

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

    printf("\n
Average Turnaround Time = %.2f",
           avg_tat / 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