\"Writing.Com
*Magnify*
SPONSORED LINKS
Printed from https://writing.com/main/profile/notebook/raskin
Please follow an 18+ rating.*
//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. *Think*
*Party* Happy Writing.Com account anniversary. *Party*



"Note: Have you claimed your [Image #697791] ? ?..."
* Content and content ratings in this area are monitored solely by this member. Page owners have the ability to remove posts and/or block posters who do not follow the content rating or who post unwanted content. In addition, each member can block/ignore another member using the Block/Ignore Members" link on the Account Options screen.
Printed from https://writing.com/main/profile/notebook/raskin