NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


edit
play_arrow

brightness_4
// C program for Highest Response Ratio Next (HRRN) Scheduling
#include <stdio.h>

// Defining process details
struct process {
char name;
int at, bt, ct, wt, tt;
int completed;
float ntt;
} p[10];

int n;

// Sorting Processes by Arrival Time
void sortByArrival()
{
struct process temp;
int i, j;

// Selection Sort applied
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {

// Check for lesser arrival time
if (p[i].at > p[j].at) {

// Swap earlier process to front
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
}

void main()
{
int i, j, t, sum_bt = 0;
char c;
float avgwt = 0, avgtt = 0;
n = 5;

// predefined arrival times
int arriv[] = { 0, 2, 4, 6, 8 };

// predefined burst times
int burst[] = { 3, 6, 4, 5, 2 };

// Initializing the structure variables
for (i = 0, c = 'A'; i < n; i++, c++) {
p[i].name = c;
p[i].at = arriv[i];
p[i].bt = burst[i];

// Variable for Completion status
// Pending = 0
// Completed = 1
p[i].completed = 0;

// Variable for sum of all Burst Times
sum_bt += p[i].bt;
}

// Sorting the structure by arrival times
sortByArrival();
printf("nNametArrival TimetBurst TimetWaiting Time");
printf("tTurnAround Timet Normalized TT");
for (t = p[0].at; t < sum_bt;) {

// Set lower limit to response ratio
float hrr = -9999;

// Response Ratio Variable
float temp;

// Variable to store next processs selected
int loc;
for (i = 0; i < n; i++) {

// Checking if process has arrived and is Incomplete
if (p[i].at <= t && p[i].completed != 1) {

// Calculating Response Ratio
temp = (p[i].bt + (t - p[i].at)) / p[i].bt;

// Checking for Highest Response Ratio
if (hrr < temp) {

// Storing Response Ratio
hrr = temp;

// Storing Location
loc = i;
}
}
}

// Updating time value
t += p[loc].bt;

// Calculation of waiting time
p[loc].wt = t - p[loc].at - p[loc].bt;

// Calculation of Turn Around Time
p[loc].tt = t - p[loc].at;

// Sum Turn Around Time for average
avgtt += p[loc].tt;

// Calculation of Normalized Turn Around Time
p[loc].ntt = ((float)p[loc].tt / p[loc].bt);

// Updating Completion Status
p[loc].completed = 1;

// Sum Waiting Time for average
avgwt += p[loc].wt;
printf("n%ctt%dtt", p[loc].name, p[loc].at);
printf("%dtt%dtt", p[loc].bt, p[loc].wt);
printf("%dtt%f", p[loc].tt, p[loc].ntt);
}
printf("nAverage waiting time:%fn", avgwt / n);
printf("Average Turn Around time:%fn", avgtt / n);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.