c program for first come first serve scheduling

c program for first come first serve scheduling. This c program computes average and total waiting time and turn around time of processes. c program for first come first serve gives practical knowledge of how a operating system perform task scheduling.

c program for first come first serve scheduling

#include<stdio.h>
#include<conio.h>

void display();
void getdata();
void waitTime();
void turnAroundTime();

int n, a[100],b[100];

int main()
{
    printf("***** FCFS ( FIRST COME FIRST SERVE ) SCHEDULING ******\n\n");

    getdata();
    display();
    waitTime();
    turnAroundTime();
    getch();
}

void getdata()
{   
    char c;
    printf("Enter the number of process ");
    scanf("%d",&n);

    printf("\nDo you need to enter the arrival time of process [y/n] or [Y/N]\n");
    scanf("%s",&c);

    for(int i=0; i<n; i++)
    {
          printf("Enter the %d process burst time : ",i+1);
          scanf("%d",&b[i]);
          if(c=='y' || c=='Y')
          {
                  printf("Enter the %d process arrival time : ",i+1);
                  scanf("%d",&a[i]);
          }
          else
          {
                  a[i]=0;
          }
    }
}

void display()
{
     printf("\nPROCESS\tBURST TIME\tARRIVAL TIME6\n");
     for(int i=0; i<n; i++)
     {
             printf("    %d\t      %d\t      %d\n",i+1,b[i],a[i]);
     }
}

void waitTime()
{
     int w[100];
     float totalWait=0;
     w[0]=0;
     for(int i=1; i<n; i++)
     {
           w[i]=b[i-1]-a[i]+w[i-1];
           totalWait=w[i]+totalWait;
     }
     printf("\nTotal Waiting time = %f",totalWait);
     printf("\nAverage Waiting time = %f",totalWait); 
}

void turnAroundTime()
{
     int tat[100];
     float totalTat=0;
     tat[-1]=0;
     for(int i=0; i<n; i++)
     {
             tat[i]=b[i]-a[i]+tat[i-1];               
             totalTat=totalTat+tat[i];
     }
     printf("\n\nTotal Turn Around Time(TAT) = %f",totalTat);
     printf("\nAverage Turn Around Time Avg.(TAT) = %f",totalTat/n);
}


Output :

c program for first come first serve
c program for first come first serve

9 thoughts on “c program for first come first serve scheduling”

  1. this one is much better

    #include
    int main()
    { int n,i,f=0;
    float ta=0,tw=0;
    printf(“enter the number of processes”);
    scanf(“%d”,&n);
    char p[n][10];
    int a[n+1],b[n+1],w[n+1],t[n+1];
    w[0]=0,b[0]=0,a[0]=0;
    for(i=1;i<=n;i++)
    {
    printf("enter name,arrival time and burst time of process %d:\n",i);
    scanf("%s %d %d",p[i],&a[i],&b[i]);
    }
    printf("name at bt wt ta\n");
    for(i=1;i<=n;i++)
    {
    w[i]=b[i-1]-a[i]+w[i-1];
    t[i]=w[i]+b[i];
    printf("%s\t%d\t%d\t%d\t%d\n",p[i],a[i],b[i],w[i],t[i]);
    tw+=w[i];
    ta+=t[i];
    }
    printf("average waiting time=%f\n",tw/n);
    printf("average T.A=%f",ta/n);
    return 0;
    }

  2. in above program arrival time is zero,this is not applicable in this program in which arrival time is not zero

  3. try this
    #include
    #include
    #include
    void main()
    {
    clrscr();
    int n,a[10],b[10],t[10],w[10],g[10],i,m;
    float att=0,awt=0;
    for(i=0;i<10;i++)
    {
    a[i]=0; b[i]=0; w[i]=0; g[i]=0;
    }
    printf("enter the number of process:\n");
    scanf("%d",&n);
    printf("enter the arrival times:\n");
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    printf("enter the burst times:\n");
    for(i=0;i<n;i++)
    scanf("%d",&b[i]);
    g[0]=0;
    for(i=0;i<10;i++)
    g[i+1]=g[i]+b[i];
    for(i=0;i<n;i++)
    {
    w[i]=g[i]-a[i];
    t[i]=g[i+1]-a[i];
    awt=awt+w[i];
    att=att+t[i];
    }
    awt =awt/n;
    att=att/n;
    printf("\n\tprocess\t A_time\t B_time\t W_time\t TA_time\n");
    for(i=0;i<n;i++)
    {
    printf("\tp%d\t%d\t%d\t%d\t%d\n",i,a[i],b[i],w[i],t[i]);
    }
    printf("the average waiting time is :%f\n",awt);
    printf("the average turn around time is :%f\n",att);
    getch();
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>