c program to implement non preemptive priority scheduling algorithm

Solutions on MaxInterview for c program to implement non preemptive priority scheduling algorithm by the best coders in the world

showing results for - "c program to implement non preemptive priority scheduling algorithm"
Ana Paula
03 Jul 2018
1#include<stdio.h>
2 
3int main()
4{
5    int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
6    printf("Enter Total Number of Process:");
7    scanf("%d",&n);
8 
9    printf("\nEnter Burst Time and Priority\n");
10    for(i=0;i<n;i++)
11    {
12        printf("\nP[%d]\n",i+1);
13        printf("Burst Time:");
14        scanf("%d",&bt[i]);
15        printf("Priority:");
16        scanf("%d",&pr[i]);
17        p[i]=i+1;           //contains process number
18    }
19 
20    //sorting burst time, priority and process number in ascending order using selection sort
21    for(i=0;i<n;i++)
22    {
23        pos=i;
24        for(j=i+1;j<n;j++)
25        {
26            if(pr[j]<pr[pos])
27                pos=j;
28        }
29 
30        temp=pr[i];
31        pr[i]=pr[pos];
32        pr[pos]=temp;
33 
34        temp=bt[i];
35        bt[i]=bt[pos];
36        bt[pos]=temp;
37 
38        temp=p[i];
39        p[i]=p[pos];
40        p[pos]=temp;
41    }
42 
43    wt[0]=0;	//waiting time for first process is zero
44 
45    //calculate waiting time
46    for(i=1;i<n;i++)
47    {
48        wt[i]=0;
49        for(j=0;j<i;j++)
50            wt[i]+=bt[j];
51 
52        total+=wt[i];
53    }
54 
55    avg_wt=total/n;      //average waiting time
56    total=0;
57 
58    printf("\nProcess\t    Burst Time    \tWaiting Time\tTurnaround Time");
59    for(i=0;i<n;i++)
60    {
61        tat[i]=bt[i]+wt[i];     //calculate turnaround time
62        total+=tat[i];
63        printf("\nP[%d]\t\t  %d\t\t    %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
64    }
65 
66    avg_tat=total/n;     //average turnaround time
67    printf("\n\nAverage Waiting Time=%d",avg_wt);
68    printf("\nAverage Turnaround Time=%d\n",avg_tat);
69 
70	return 0;
71}
72
queries leading to this page
c program to demonstrate the concept of preemptive priority scheduling algorithmpriority scheduling algorithm in c 2b 2b with arrival time onlinepreemptive priority scheduling algorithm in cpreemptive priority scheduling lower order code in cpriority scheduling algorithm program non preemptivec program for non preemptive priority schedulingpriority preemptive scheduling program in cimplementation of priority scheduling algorithm in cpriority scheduling algorithm in cnon pre emptive priority scheduling program in cpreemptive priority scheduling algorithm program in cto write a e2 80 98c e2 80 99 program to perform priority scheduling preemptive priority scheduling ascending order in cpriority scheduling non preemptive in cpriority non preemptive scheduling program in cwrite a program in c to implement non preemptive priority schedulingnon preemptive priority scheduling program in c programnon preemptive priority scheduling program in cpriority scheduling preemptive program in chow is priority decided in priority queue cpu scheduling algorithmpriority scheduling program in c non preamptivepriority scheduling program in cpseudo code for priority schedulingc 2b 2b program for priority scheduling algorithmpreemptive priority scheduling algorithm in c using structurenon preemptive priority scheduling in cpriority based logic in codingpre emptive priority scheduling algorithm in csjf preemptive scheduling program in c 2b 2bpreemptive priority scheduling algo in cc program priority scheduling schedulingnpp scheduling algorithm in cpriority scheduling c programwrite a program to implement the priority scheduling algorithm priority algorithm in cto implement preemptive priority scheduling algorithm cpreemptive priority scheduling algorithm in c using structureec program priority schedulingnon preemptive priority cpu scheduling algorithm in cpriority scheduling programnon preemptive priority scheduling codepreemptive based priority scheduling gfgpriority non preemptive scheduling program in c 2b 2b with outputpreemptive priority scheduling in cc program to implement non preemptive priority scheduling algorithmpreemptive priority scheduling program in cc program for preemptive priority schedulingpriority scheduling algorithm in cppimplement priority cpu scheduling algorithmpriority scheduling in c 23preemptive priority scheduling c programc program to implement non preemptive priority scheduling algorithm