You are on page 1of 7

ANSWER:ALGORITHM FOR FIRST COME FIRST SERVE:1.SET PRT:=BEGINNING 2.INPUT NO OF PROCESS, PROCESS NAME, PROCESS TIME. 3.

CALCULATE WATING TIME, AVG. TIME. 4.OUTPUT THE REQUIRED. 5.END

Algorithm for Shortest job first: 1.SET PTR:=BEGINNING 2.INPUT NO OF PROCESS, PROCESS NAME, PROCESS TIME. 3.SORT THE PROCESS IN THE ASSENDING ORDER OF PROCESS TIME. 4.ARRIANGE THE JOBS/PROCESS ACCORDING TO SORTED PROCESS TIME. 5.CALCULATE WATING TIME, AVG. TIME. 6.OUTPUT THE REQUIRED. 7.END

ALGORITHM FOR PRIORITY SCHEDUING:1.SET PRT:=BEGINNING. 2.INPUT NO OF PROCESS, PROCESS NAME, PROCESS TIME,PRIORITY ORDER. 3.ARRIANGE THE JOBS/PROCESS ACCORDING TO PRIORITY ORDER. 4.CALCULATE WATING TIME, AVG. TIME. 5.OUTPUT THE REQUIRED. 6.END

1. PROGRAM FOR FIRST COME FIRST SERVE #include<string.h> #include<stdio.h> #include<conio.h> #include<process.h> main() { char p[10][5],temp[5]; int n,pt[10],et[10],wt[10],tot=0,i,j,temp1; float avg=0;

printf("Enter the number of processes:"); scanf("%d",&n);

for(i=0;i<n;i++) { printf("Enter process %d name:\n",i+1); scanf("%s",&p[i]); printf("Enter process time"); scanf("%d",&pt[i]); et[i]=pt[i]; }

wt[0]=0;

for(i=1;i<n;i++) { wt[i]=wt[i-1]+pt[i-1];

tot=tot+wt[i]; } avg=(float)tot/n; printf("Prog_name\t Prog_time\t waiting_time\n"); for(i=0;i<n;i++) printf("%s\t %d \t %d\n",p[i],pt[i],wt[i]); printf("Total waiting time=%d\n Avg waiting time=%f",tot,avg); getch(); }

2. PROGRAM FOR SHORTEST JOB FIRST #include<string.h> #include<stdio.h> #include<conio.h> #include<process.h> main() { char p[10][5],temp[5]; int n,pt[10],et[10],wt[10],tot=0,i,j,temp1; float avg=0;

printf("Enter the number of processes:"); scanf("%d",&n);

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

printf("Enter process %d name:\n",i+1); scanf("%s",&p[i]); printf("Enter process time"); scanf("%d",&pt[i]); et[i]=pt[i]; }

for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(pt[i]>pt[j]) { temp1=pt[i]; pt[i]=pt[j]; pt[j]=temp1; strcpy(temp,p[i]); strcpy(p[i],p[j]); strcpy(p[j],temp); } } }

wt[0]=0;

for(i=1;i<n;i++) { wt[i]=wt[i-1]+pt[i-1];

tot=tot+wt[i]; } avg=(float)tot/n; printf("Prog_name\t Prog_time\t waiting_time\n"); for(i=0;i<n;i++) printf("%s\t %d \t %d\n",p[i],pt[i],wt[i]); printf("Total waiting time=%d\n Avg waiting time=%f",tot,avg); getch(); }

3. PROGRAM FOR PRIORITY SCHEDULING #include<string.h> #include<stdio.h> #include<conio.h> #include<process.h> main() { char p[10][5],temp[5]; int n,pt[10],et[10],wt[10],tot=0,i,j,temp1; float avg=0;

printf("Enter the number of processes:"); scanf("%d",&n);

for(i=0;i<n;i++) { printf("Enter process %d name:\n",i+1); scanf("%s",&p[i]);

printf("Enter process time"); scanf("%d",&pt[i]); printf("Enter the priority of %d process",i+1); scanf("%d",&et[i]); }

for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(et[i]>et[j]) { temp1=et[i]; et[i]=et[j]; et[j]=temp1; strcpy(temp,p[i]); strcpy(p[i],p[j]); strcpy(p[j],temp); } } }

wt[0]=0;

for(i=1;i<n;i++) { wt[i]=wt[i-1]+pt[i-1]; tot=tot+wt[i];

} avg=(float)tot/n; printf("Prog_name\t Prog_time\t Priority\t waiting_time\n"); for(i=0;i<n;i++) printf("%s\t %d\t %d\t %d\n",p[i],pt[i],et[i],wt[i]); printf("Total waiting time=%d\n Avg waiting time=%f",tot,avg); getch(); }

You might also like