os lab programs
DESCRIPTION
os lab programsTRANSCRIPT
/* SJF CPU SCHEDULING ALGORITHM*/
#include<stdio.h>#include<conio.h>
void main(){
int i,j,n,bt[10],st[10],et[10],wt[10],temp,tot;/* n=number of jobs bt=burst time st=starting time wt=waiting time*//*et=end time*/float avg;clrscr();printf("ENTER THE NO.OF JOBS");scanf("%d",&n);for(i=1;i<=n;i++){
printf("\n \n ENTER %d PROCESS BURST TIME",i);scanf("%d",&bt[i]);
}/* SWAPPING BURST TIMES*/for(i=1;i<=n;i++){
for(j=i+1;j<=n;j++){
if(bt[i]>bt[j]){
temp=bt[i];bt[i]=bt[j];bt[j]=temp;
}}/* IN CASE OF FIRST JOB*/if(i==1){
st[1]=0;et[1]=bt[1];wt[1]=0;
}/* FOR REMAINING CASES*/else{
st[i]=et[i-1];et[i]=st[i]+bt[i];wt[i]=st[i];
}}printf("\n\n BURST TIME \t STARTING TIME \t END TIME \t WAIT TIME\n");printf("\n ********************************************************\n");for(i=1;i<=n;i++){
printf("\n %5d %15d %15d %15d",bt[i],st[i],et[i],wt[i]);}printf("\n ********************************************************\n");
1
for(i=1,tot=0;i<=n;i++)tot+=wt[i];avg=(float)tot/n;printf("\n\n\n AVERAGE WAITING TIME=%f",avg);for(i=1,tot=0;i<=n;i++)tot+=et[i];avg=(float)tot/n;printf("\n\n AVERAGE TURNAROUND TIME=%f",avg);for(i=1,tot=0;i<=n;i++)tot+=st[i];avg=(float)tot/n;printf("\n\n AVERAGE RESPONSE TIME=%f",avg);getch();
}
2