Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
1.4 kB
3
Indexable
Never
  GNU nano 6.2                                                                                                                    fcfs.c *                                                                                                                           
#include<stdio.h>
int main()
 {
  int min,temp,bt[20],i,j,at[20],wt[20],tat[20],n;
  float wtavg,tatavg;
   printf("enter the number of processes--");
   scanf("%d",&n);
    for(i=0;i<n;i++)
     {
      printf("\nenter the arrival time for processes%d--",i);
      scanf("%d",&at[i]);
     }
      for(i=0;i<n-1;i++)
       {
        min=i;
        for(j=i+1;j<n;j++)
         {
          if(at[min]>at[j])
          min=j;
       if(i!=min)
        {
         at[temp]=at[i];
         at[i]=at[min];
         at[min]=at[temp];
        }
       }
     }
     for(i=0;i<n;i++)
      {
       printf("\nenter Burst time for processes%d--",i);
       scanf("%d",&bt[i]);
      }
wt[0]=wtavg=0;
tat[0]=bt[0];
    for(i=1;i<n;i++)
     {
       wt[i]=wt[i-1]+bt[i-1];
       tat[i]=tat[i-1]+bt[i];
       wtavg=wtavg+wt[i];
       tatavg=tatavg+tat[i];
     }
printf("\nprocess\tburst time\twaiting time\tturnaround time\n");
for(i=0;i<n;i++)
printf("\n\tP%d\t\t%d\t\t%d\t\t%d",i,bt[i],wt[i],tat[i]);
printf("\nAverage waiting time--%f",wtavg);
printf("\nAverage turnaround time--%f",tatavg);
return 0;
}
-




Leave a Comment