0% found this document useful (0 votes)
4 views6 pages

#Includestdio

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)
4 views6 pages

#Includestdio

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/ 6

#include <stdio.

h>

!!!

void findWaitingTime(int processes[], int n, int bt[], int wt[])

wt[0] = 0;

for (int i = 1; i < n; i++)

wt[i] = bt[i - 1] + wt[i - 1];

void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[])

for (int i = 0; i < n; i++)

tat[i] = bt[i] + wt[i];

void findavgTime(int processes[], int n, int bt[])

int wt[n], tat[n], total_wt = 0, total_tat = 0;

findWaitingTime(processes, n, bt, wt);

printf("Processes Burst time Waiting time Turn around time\n");

find TurnAroundTime(processes, n, bt, wt, tat);

for (int i = 0; i < n; i++)

total_wt = total_wt + wt[i];

total_tat = total_tat + tat[i];

printf("%d ", (i + 1));

printf("%d", bt[i]);

printf("%d", wt[i]);

printf("%d\n", tat[i]);

}
int s = (float) total_wt / (float) n;

int t = (float) total_tat / (float) n

printf("%d", wt[i]);

printf("%d\n", tat[i]);

int s = (float) total_wt / (float) n;

int t - (float) total_tat / (float) n;

printf("Average waiting time = %d", s);

printf("\n");

printf("Average turn around time = %d ", t);

int main()

int processes[] = { 1,2,3};

int n = sizeof processes / sizeof processes[0];

int burst_time[] = { 10,5,8};

findavgTime(processes, n, burst_time);

return 0;

}
CPU Scheduling Algorithm - SJF!!!

#include <stdio.h>

void main({ int bt[10], i, j, wt[10], ft[10], temp, temp_id, p[10], st[10], tt[10];

int no;

int wat = 0, att = 0;

printf("\nEnter the no of process:- ");

scanf("%d", &no);

for (i = 1; i <= no; i++)

printf("\nEnter the process id:- ");

scanf("%d", &p[i]);

for (i = 1; i <= no; i++)

printf("\nEnter burst time of the process :- ");

scanf("%d", &bt[i]);

//Sorting

for (i = 1; i <= no; i++)

for (j = 1; j <= no - 1; j++)

if (bt[j + 1] < bt[j])

{
temp - bt[j];

bt[j] = bt[j + 1];

bt[j + 1] = temp;

tomn id[

temp_id = p[j]; P[j] = p[j + 1]; p[j + 1] = temp_id;

}-

\n ");

printf("\n -

printf("Sorted input is:");

for (i = 1; i <= no; i++)

printf("\np%d\t\t%d", p[i], bt[i]);

for (i = 1; i <= no; i++)

if (i == 1)

st[i] = 0;

ft[i] = bt[i];

else

st[i] = st[i - 1] + bt[i - 1];

ft[i] = st[i] + bt[i];

}
printf("\n -

printf("BurstTime WaitingTime TurnAroundTime"); -

\n ");

for (i = 1; i <= no; i++)

wt[i] = st[i];

for (i = 1; i <= no; i++)

tt[i] = ft[i];

for (i = 1; i <= no; i++)

printf("\n%d\t\t\t%d\t\t\t\t%d", bt[i], wt[i], tt[i]);

printf("\n- -

\n ");

//Average waiting time

int sum = 0;

for (i = 1; i <= no; i++)

sum = sum + wt[i];

wat - sum / no; sum = 0;


for (i = 1; i <= no; i++)

sum = sum + tt[i];

att - sum / no; printf("\nAverage waitng time:- %d", wat); printf("\nAverage turn around
time :-%d", att);

You might also like