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

Code SJF

The document is a C program that implements a scheduling algorithm for processes based on their burst times. It prompts the user to enter the number of processes and their respective burst times, sorts the processes by burst time, and calculates the waiting time for each process. Finally, it outputs the waiting times and the average waiting time for all processes.

Uploaded by

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

Code SJF

The document is a C program that implements a scheduling algorithm for processes based on their burst times. It prompts the user to enter the number of processes and their respective burst times, sorts the processes by burst time, and calculates the waiting time for each process. Finally, it outputs the waiting times and the average waiting time for all processes.

Uploaded by

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

#include<stdio.

h>
struct process
{
int id;
int brust;
};
typedef struct process proc;
int main()
{
int n;
printf("enter the number of processs: ");
scanf("%d", &n);
proc p[n], temp;
int i,j;
for(i=0;i<n;i++)
{
p[i].id=i;
printf("enter the brust time of process P %d :", i);
scanf("%d", &p[i].brust);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(p[j].brust < p[i].brust)
{
temp.id = p[j].id;
temp.brust = p[j].brust;
p[j].id = p[i].id;
p[j].brust = p[i].brust;
p[i].id = temp.id;
p[i].brust = temp.brust;
}
}

} int wt=0;
int twt=0;
printf("\n scheduling information \n");
for(i=0;i<n;i++)
{
twt = twt+wt;
printf("process id: %d \t wating time: %d \n",p[i].id, wt
);
wt=wt+p[i].brust;
}
printf("\n average waiting time: %1.2f :",
((float)twt/n));
return 0;
}

You might also like