//FCFS #include<stdio.h> int main(){ int i,n,sum=0; float avg; printf("Enter Number process: "); scanf("%d",&n); int bt[n],wt[n]; for(i=0; i<n; i++){ printf("P[%d] =>",i+1); scanf("%d",&bt[i]); } printf("\nFCFS:\n"); for(i=0; i<n; i++){ wt[i]=wt[i-1]+bt[i-1]; wt[0]=0; printf("Waiting Time of P[%d]=%d\n",i+1,wt[i]); sum=sum+wt[i]; } avg=sum/(float)n; printf("\nAVG Waiting Time: %.2f\n", avg); return 0; } //SJF #include<stdio.h> int main(){ int i,j,n,sum=0; float avg; printf("Enter Number process: "); scanf("%d",&n); int bt[n],wt[n],p[n]; for(i=0; i<n; i++){ printf("P[%d] =>",i+1); scanf("%d",&bt[i]); p[i]=i+1; } printf("\nSJF:\n"); for (i = 0; i<n ; i++){ for (j = i+1; j<n; j++){ if (bt[i]>bt[j]){ int temp=bt[i]; bt[i]=bt[j]; bt[j]=temp; temp=p[i]; p[i]=p[j]; p[j]=temp; }}} for(i=0; i<n; i++){ wt[i]=wt[i-1]+bt[i-1]; wt[0]=0; printf("Waiting Time of P[%d]=%d\n",p[i],wt[i]); sum=sum+wt[i]; } avg=sum/(float)n; printf("\nAVG Waiting Time: %.2f\n", avg); return 0; } |
No idea what you're trying to do, but the code isn't working. |