0% found this document useful (0 votes)
21 views1 page

Priority C

The document contains code for a C program that sorts processes by priority and calculates their waiting times and turnaround times. It takes in the number of processes, their burst times and priorities, sorts them by priority, and calculates their waiting times and turnaround times as well as the average times.

Uploaded by

akvakarthik2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Priority C

The document contains code for a C program that sorts processes by priority and calculates their waiting times and turnaround times. It takes in the number of processes, their burst times and priorities, sorts them by priority, and calculates their waiting times and turnaround times as well as the average times.

Uploaded by

akvakarthik2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

5/9/24, 7:26 AM Priority.

Priority.c

1 #include <stdio.h>
2
3 void main()
4 {
5 int p[20], bt[20], pri[20], wt[20], tat[20], i, j, n, temp;
6 float twt, ttat;
7
8 printf("Enter the no.of processes: ");
9 scanf("%d", &n);
10 // Reading Burst time and Priority
11 for (i = 0; i < n; i++)
12 {
13 p[i] = i + 1;
14 printf("Enter the Burst Time of Process %d: ", i + 1);
15 scanf("%d", &bt[i]);
16 printf("\nEnter the Priority of Process %d: ", i + 1);
17 scanf("%d", &pri[i]);
18 }
19 // Sorting Priority (also burst time and process id) in ascending order
20 for(i = 0; i < n-1; i++)
21 {
22 for(j = 0; j < n-1-i; j++)
23 {
24 if (pri[j] > pri[j+1])
25 {
26 temp = pri[j];
27 pri[j] = pri[j+1];
28 pri[j+1] = temp;
29
30 temp = bt[j];
31 bt[j] = bt[j+1];
32 bt[j+1] = temp;
33
34 temp = p[j];
35 p[j] = p[j+1];
36 p[j+1] = temp;
37 }
38 }
39 }
40 // Calculating Waiting time, TurnAround Time and averages
41 twt = wt[0] = 0;
42 ttat = tat[0] = bt[0];
43 for (i = 1; i < n; i++)
44 {
45 wt[i] = wt[i - 1] + bt[i - 1];
46 tat[i] = tat[i - 1] + bt[i];
47 twt += wt[i];
48 ttat += tat[i];
49 }
50 // Printing data
51 printf("\nPROCESS\t\tPRIORITY\tBURST TIME\tWAITING TIME\tTURNAROUND TIME");
52 for (i = 0; i < n; i++)
53 {
54 printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ", p[i], pri[i], bt[i], wt[i], tat[i]);
55 }
56 printf("\nAverage Turnaround Time: %.2f", ttat / n);
57 printf("\nAverage Waiting Time: %.2f", twt / n);
58 }

localhost:56984/cfbb2c2f-d3d1-4f0d-b35a-11003518cc9f/ 1/1

You might also like