First Come First Serve

DATE : 22/09/2020

AIM

To implement process scheduling using FCFS algorithm

Algorithm

  1. Start
  2. Declare array size
  3. Read the number of process to be inserted
  4. Read the arrival time of process
  5. Read the burst time of process
  6. Calculate the waiting time of each process wt[i]=tat[i]-bt[i]
  7. Calculate the turnaround time of each process tat[i]=ct[i]-at[i]
  8. Calculate the average waiting time and average turnaround time
  9. Display the values
  10. Stop

Program

#include<stdio.h>

int main() {
  int n, at[20], bt[20], ct[20], tat[20], wt[20], i, j, k, sum = 0;
  float avwt = 0, avtat = 0;
  printf("Enter the total no of processes:");
  scanf("%d", & n);

  printf("Enter Arrival time:");
  for (i = 0; i < n; i++) {
    printf("P(%d):", i + 1);
    scanf("%d", & at[i]);
  }
  printf("Enter Burst time:");
  for (i = 0; i < n; i++) {
    printf("P(%d):", i + 1);
    scanf("%d", & bt[i]);
  }
  for (j = 0; j < n; j++) {
    sum = sum + bt[j];
    ct[j] = ct[j] + sum;
  }
  wt[0] = 0; //waiting time of process 1 //calculating waiting Time for(i=1;i<n;i++)
  {
    wt[i] = 0;
    for (k = 0; k < i; k++) {
      wt[i] += bt[k];
    }
  }
  printf("Process\\\\Arrival Time\\\\Burst Time\\\\Completion Time\\\\Turnaround Time\\\\Waiting Time\\n");
  for (i = 0; i < n; i++) {
    tat[i] = ct[i] - at[i];
    wt[i] = tat[i] - bt[i];
    avwt += wt[i];
    avtat += tat[i];
    printf("\\nP[%d]\\t%d\\t%d\\t%d\\t%d\\t%d", i, at[i], bt[i], ct[i], tat[i], wt[i]);
  }

  avwt /= n;
  avtat /= n;
  printf("\\n\\nAverage turnaround time is %f", avtat);
  printf("\\nAverage waiting time is %f\\n\\n", avwt);
  return 0;
}

Output

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/22e5003d-cb90-453f-b6a7-7f57b2e64a12/Screen_Shot_2020-12-04_at_10.17.18_AM.png

Result