Advertisement
JagadeeshUndavalli

FCFS..

May 7th, 2022 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct process
  4. {
  5.   char name[5];
  6.   int burst;
  7. };
  8.  
  9. int
  10. main ()
  11. {
  12.   int size;
  13.   int warr[size + 1];
  14.   int carr[size+1];
  15.   printf ("\nEnter the number of processes  : ");
  16.   scanf ("%d", &size);
  17.   struct process arr[size];
  18.   struct process Process;
  19.   printf ("\nEnter the process name and burst time  : \n");
  20.   for (int i = 0; i < size; i++)
  21.     {
  22.       printf("\t-->\t");
  23.       scanf ("%s", Process.name);
  24.       scanf ("%d", &Process.burst);
  25.       arr[i] = Process;
  26.     }
  27.   float waiting = 0,complete=0;
  28.   warr[0] = 0;
  29.   for(int i=0;i<size;i++){
  30.       warr[i+1] = warr[i]+arr[i].burst;
  31.       waiting += warr[i];
  32.   }
  33.  
  34.   for(int i=0;i<size;i++){
  35.       carr[i] = arr[i].burst + warr[i];
  36.       complete+=carr[i];
  37.   }
  38.   printf("Process\tBurst Time\tWaiting Time\tCompletion Time\n");
  39.   for(int i=0;i<size;i++){
  40.       printf("%s\t%d ms\t\t%d ms\t\t%d ms\n",arr[i].name,arr[i].burst,warr[i],carr[i]);
  41.   }
  42.  
  43.    
  44.   printf ("\nAverage Waiting Time : %.2f ms", waiting / size);
  45.  
  46.   printf ("\nAverage Completion Time : %.2f ms\n", complete / size);
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement