Escolar Documentos
Profissional Documentos
Cultura Documentos
#include<stdio.h> #include< conio.h> #include<string.h> Void main() { Int bt[10],i, n, wt=0, awt=0, twt=0;
Char pname[10][10]; Printf(enter no. of processes); Scanf(%d, &n); For(i=0;i<n;i++) { Printf(enter the process %d name, i+1); Scanf(%s, &pname[i]); Printf(enter burst time); Scanf(%d, &bt[i]); } Printf(\n FCFS Scheduling Algorithm); Printf(\n Process \t Burst time \t \t waiting time); For(i=0;i<n;i++) {
twt=twt+wt; Printf(\n %s \t %d \t %d \n, pname[i], bt[i], wt); Wt=wt+bt[i]; } Awt=(twt)/n; Printf(average waiting time %d, awt); Getch(); }
Output: enter no. of processes Enter process name Enter burst time Enter process name Enter burst time Enter process name Enter burst time
3 p1 7 p2 6 p3 9
/* WRITE A PROGRAM FOR SJF SCHEDULING ALGORITHM */ #include< stdio.h> #include<conio.h> Void main() { Int n, bt[10],i, wt=0,twt=0, j; Float awt=0; Clrscr(); Printf(enter no. of processes); Scanf(%d &n); For(i=0;i<n; i++) { Printf( enter burst time %d, i+1); Scanf(%d, &bt[i]); } Printf(\n SJF SCHEDULING ALGORITHM); Printf(\n burst time \t waiting time); For(i=0; i<n; i++) { For(j=i+1;j<n;j++)
{ If(bt[i] >bt[j]) { T=bt[i]; Bt[i]=bt[j]; Bt[j]=t; } } } For(i=0;i<n ;i++) { twt=twt+wt; Printf( %d \t %d \n, bt[i], wt); Wt=wt+bt[i]; } Awt=(twt)/n; Printf(average waiting time %d, awt); Getch(); } Output: enter no. of processes 3 Enter burst time1 Enter burst time2 Enter burst time3 6 8 9
SJF SCHEDULING ALGORITHM Burst time 6 8 9 Average waiting time waiting time 0 6 14 6.66
#include<stdio.h> #include< conio.h> Void main() { Int I,j, n, a[10], wt[10], k, tat[10], prt[10], s=0,p=0; Float awt, atat; Clrscr(); Printf( enter no. of processes); Scanf(%d, &n); Printf( enter execution times and priorities); For(i=0;i<n;i++) {
Scanf(%d }
%d , &a[i], &prt[i]);
For(i=0;i<n;i++) For(j=i+1; j<n;j++) { If(prt[i]>prt[j]) { T= prt[i]; Prt[i]= prt[j]; Prt[j]= t; K=a[i]; A[i]=a[j]; A[j]= k; } } Printf( the order of execution times and priorities after sorting); For(i=0;i<n;i++) { Printf(\n %d \t %d , a[i], prt[i]); } Wt[0]=0; Tat[0]=a[0];
For(i=1;i<n;i++) { Wt[i]= wt[i+1] + a[i+1]; Tat[i]= tat[i-1]+ a[i]; } Printf(the waiting time and turn around times are \n); For(i=0;i<n;i++) { Printf(\n %d \t %d , wt[i], tat[i]); S=s+wt[i]; P=p+tat[i]; } Awt=s/n; Atat=p/n; Printf( \n average waiting time is %f, awt); Printf(\n average turn around time is %f, atat); Getch(); }
Output:
9 6
1 4
/* WRITE A PROGRAM FOR ROUND ROBIN SCHEDULING ALGORITHM*/ #include <stdio.h> #include<conio.h> Void main() { Int s=0, n,a[10], tat[10],tq=5,cnt=0, t=0, i ; Float atat=0.0; Clrscr(); Printf(enter the no. of processes);
Scanf(%d, &n); Printf(enter execution times); For(i=0;i<n;i++) Scanf(%d, &a[i]); While(cnt<n) { For(i=0;i<n;i++) { If(a[i]==0) { Cnt++; Continue; } Else if (a[i]<=tq) { T=t+a[i]; A[i]=0; Tat[i]=t; } Else if(a[i]>tq) { A[i]=a[i]-tq; T=t+tq;
} } } For(i=0;i<n;i++) { Printf(\n %d , tat[i]); S=s+tat[i]; } Atat=s/n; Printf(\n average turn around time is %f, atat); Getch(); } Output: enter no. of processes 2 Enter execution times 9 13 17 Average turn around time is 15.0 8