Shortest-Job-First (SJR) or non-preemptive sjf cpu scheduling in c
On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
code in C:#include <stdio.h> int main() { int i,j,a[10],b[10],temp[10],temp1,avg=0,tt=0,n; printf("enter the number of Processes:\n"); scanf("%d",&n); printf("enter arrival time\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("enter burst time\n"); for(i=0;i<n;i++) scanf("%d",&b[i]); for(i=1;i<n;i++) for(j=1;j<n;j++) if(b[j]>b[j+1]) { temp1=b[j]; b[j]=b[j+1]; b[j+1]=temp1; } temp[0]=0; for(i=0;i<n;i++) temp[i+1]=temp[i]+b[i]; printf("\nGantt Chart\n"); for(i=0;i<n+1;i++) printf("\n%d",temp[i]); for(i=1;i<n;i++) avg=avg+temp[i]-a[i]; avg=avg/n; printf("\nThe Average WT is %d ms",avg); for(i=2;i<n+1;i++) tt=tt+temp[i]-a[i-1]; tt+=temp[1]; tt=tt/n; printf("\nThe Average TT is %d ms",tt); return 0; }output:-
enter the number of Processes: 5 enter arrival time 0 1 2 3 4 enter burst time 10 3 2 4 5 Gantt Chart 0 10 12 15 19 24 The Average WT is 9 ms The Average TT is 14 ms --------------------------------
0 comments: