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

Code1 | JustPaste.app
11 days ago2 views
👨‍💻Programming

Code1

#include <stdio.h>

int main()
{
    int n, i;
    int pid[20], at[20], bt[20], priority[20];
    int ct[20], tat[20], wt[20];
    int completed[20] = {0};
    int time = 0, count = 0;
    int highest;

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

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

        printf("\nEnter Arrival Time of P%d: ", pid[i]);
        scanf("%d", &at[i]);

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

        printf("Enter Priority of P%d: ", pid[i]);
        scanf("%d", &priority[i]);
    }

    // Scheduling
    while(count < n)
    {
        highest = -1;

        // Find highest-priority available process
        for(i = 0; i < n; i++)
        {
            if(completed[i] == 0 && at[i] <= time)
            {
                if(highest == -1 ||
                   priority[i] < priority[highest])
                {
                    highest = i;
                }
            }
        }

        // If no process has arrived
        if(highest == -1)
        {
            time++;
        }
        else
        {
            // Execute selected process completely
            time = time + bt[highest];

            ct[highest] = time;
            tat[highest] = ct[highest] - at[highest];
            wt[highest] = tat[highest] - bt[highest];

            completed[highest] = 1;
            count++;
        }
    }

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

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

    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