c program to implement non preemptive priority scheduling algorithm

#include<stdio.h>
 
int main()
{
    int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
    printf("Enter Total Number of Process:");
    scanf("%d",&n);
 
    printf("\nEnter Burst Time and Priority\n");
    for(i=0;i<n;i++)
    {
        printf("\nP[%d]\n",i+1);
        printf("Burst Time:");
        scanf("%d",&bt[i]);
        printf("Priority:");
        scanf("%d",&pr[i]);
        p[i]=i+1;           //contains process number
    }
 
    //sorting burst time, priority and process number in ascending order using selection sort
    for(i=0;i<n;i++)
    {
        pos=i;
        for(j=i+1;j<n;j++)
        {
            if(pr[j]<pr[pos])
                pos=j;
        }
 
        temp=pr[i];
        pr[i]=pr[pos];
        pr[pos]=temp;
 
        temp=bt[i];
        bt[i]=bt[pos];
        bt[pos]=temp;
 
        temp=p[i];
        p[i]=p[pos];
        p[pos]=temp;
    }
 
    wt[0]=0;	//waiting time for first process is zero
 
    //calculate waiting time
    for(i=1;i<n;i++)
    {
        wt[i]=0;
        for(j=0;j<i;j++)
            wt[i]+=bt[j];
 
        total+=wt[i];
    }
 
    avg_wt=total/n;      //average waiting time
    total=0;
 
    printf("\nProcess\t    Burst Time    \tWaiting Time\tTurnaround Time");
    for(i=0;i<n;i++)
    {
        tat[i]=bt[i]+wt[i];     //calculate turnaround time
        total+=tat[i];
        printf("\nP[%d]\t\t  %d\t\t    %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
    }
 
    avg_tat=total/n;     //average turnaround time
    printf("\n\nAverage Waiting Time=%d",avg_wt);
    printf("\nAverage Turnaround Time=%d\n",avg_tat);
 
	return 0;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
non preemptive priority cpu scheduling algorithm in c preemptive priority scheduling algorithm program in c priority preemptive scheduling program in c non preemptive priority scheduling in c preemptive priority scheduling in c preemptive priority scheduling program in c priority scheduling non preemptive in c preemptive priority scheduling c program c program for preemptive priority scheduling non pre emptive priority scheduling program in c priority non preemptive scheduling program in c++ with output priority scheduling algorithm program non preemptive pre-emptive Priority scheduling algorithm in c preemptive priority scheduling ascending order in c preemptive priority scheduling lower order code in c preemptive priority scheduling algorithm in c preemptive priority scheduling algo in c priority scheduling program in c non preamptive non preemptive priority scheduling program in c program c program for non preemptive priority scheduling preemptive priority scheduling algorithm in c using structure preemptive priority scheduling algorithm in c using structuree c program to demonstrate the concept of preemptive priority scheduling algorithm To implement preemptive priority scheduling algorithm c priority non preemptive scheduling program in c non preemptive priority scheduling program in c non preemptive priority scheduling code implementation of priority scheduling algorithm in c Write a Program to Implement the Priority Scheduling Algorithm. write a program in c to implement non preemptive priority scheduling priority algorithm in c sjf preemptive scheduling program in c++ priority scheduling preemptive program in c c program priority scheduling c program priority scheduling scheduling priority scheduling program priority scheduling algorithm in cpp priority scheduling algorithm in c++ with arrival time online priority scheduling algorithm in c how is priority decided in priority queue cpu scheduling algorithm To write a &lsquo;C&rsquo; program to perform priority scheduling. npp scheduling algorithm in c priority scheduling program in c pseudo code for priority scheduling c++ program for priority scheduling algorithm priority based logic in coding Priority Scheduling in C# preemptive based priority scheduling gfg implement priority cpu scheduling algorithm priority scheduling c program c program to implement non preemptive priority scheduling algorithm
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source