Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //precedence(arrivaltime-priority-execution)(non -pre-emptive priority scheduling using sjf[shortest job first])
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- void main()
- {
- int f=0,e=0,pri[100],c=0,d=0,n=0,pid[100],temp=0,at[100],et[100],ct[100],b=0,wt[100],tt[100],i=0,choice=1,ct1[100];
- int temp1,temp2,counti=0,count=1;
- float avgwt=0.0,avgtt=0.0;
- clrscr();
- while(choice==1)
- {
- pid[i]=count++;
- printf("\nenter arrival time:-");
- scanf("%d",&at[i]);
- printf("\nenter execution time:-");
- scanf("%d",&et[i]);
- printf("\nenter priority:-");
- scanf("%d",&pri[i]);
- i++;
- counti++;
- printf("more processes 1. yes 2. no ");
- scanf("%d",&choice);
- }
- printf("*********data entered******\n");
- printf("pid\tAT\tpri\tET\n");
- while(n!=i)
- {
- printf("%d\t",pid[n]);
- printf("%d\t",at[n]);
- printf("%d\t",pri[n]);
- printf("%d\n",et[n]);
- n++;
- }
- n=0;
- //sorting arrival time
- for(f=0;f<=i-2;f++)
- for(e=0;e<=i-2;e++)
- {
- if(at[e]>at[e+1])
- {
- temp=at[e];
- at[e]=at[e+1];
- at[e+1]=temp;
- temp=pri[e];
- pri[e]=pri[e+1];
- pri[e+1]=temp;
- temp=et[e];
- et[e]=et[e+1];
- et[e+1]=temp;
- temp2=pid[e];
- pid[e]=pid[e+1];
- pid[e+1]=temp2;
- }
- if(at[e]==at[e+1])
- {
- //sorting priority
- c=e;
- if(pri[c]>pri[c+1])
- {
- temp=pri[c];
- pri[c]=pri[c+1];
- pri[c+1]=temp;
- temp=et[c];
- et[c]=et[c+1];
- et[c+1]=temp;
- temp1=at[c];
- at[c]=at[c+1];
- at[c+1]=temp1;
- temp2=pid[c];
- pid[c]=pid[c+1];
- pid[c+1]=temp2;
- }
- if(pri[c]==pri[c+1])
- {
- //sorting et
- if(et[c]>et[c+1])
- {
- temp=et[c];
- et[c]=et[c+1];
- et[c+1]=temp;
- temp1=at[c];
- at[c]=at[c+1];
- at[c+1]=temp1;
- temp2=pid[c];
- pid[c]=pid[c+1];
- pid[c+1]=temp2;
- temp2=pri[c];
- pri[b]=pri[b+1];
- pri[b+1]=temp2;
- }
- }
- else
- {
- }
- }
- }
- /* while(cti!=i)
- {
- if(cti==0)
- ct[cti]=et[0];
- else
- {
- ct[cti]=ct[cti-1]+ct[cti];
- cti++;
- }
- } */
- d=0;
- while(d<counti)
- {
- if(d==0)
- ct[d]=et[d];
- else
- ct[d]=ct[d-1]+et[d];
- wt[d]=ct[d]-(et[d]+at[d]);
- tt[d]=ct[d]-at[d];
- d++;
- }
- printf("data after evaluation \n");
- printf("pid\tAT\tpri\tET\tCT\twt\tTT\n");
- while(n!=i)
- {
- printf("%d\t",pid[n]);
- printf("%d\t",at[n]);
- printf("%d\t",pri[n]);
- printf("%d\t",et[n]);
- printf("%d\t",ct[n]);
- printf("%d\t",wt[n]);
- printf("%d\n",tt[n]);
- n++;
- }
- n=0;
- while(n!=i)
- {
- avgwt=wt[n]+avgwt;
- avgtt=tt[n]+avgtt;
- n++;
- }
- printf("\n*******average waiting time is %f******\n",(avgwt/n));
- printf("*******average turnaound time is %f******\n",(avgtt/n));
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement