C Program for FCFS CPU scheduling algorithm

OUTPUT:
enter no of processes: 5

enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1

p_name  P_time  w_time
aaa    4    0
bbb    3    4
ccc    2    7
ddd    5    9
eee    1    14
total waiting time=34
avg waiting time=6.80

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5];
int tot=0,wt[10],i,n;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
 
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}

OUTPUT:
enter no of processes: 5

enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1

p_name  P_time  w_time
aaa    4    0
bbb    3    4
ccc    2    7
ddd    5    9
eee    1    14
total waiting time=34
avg waiting time=6.80

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

91 thoughts on “C Program for FCFS CPU scheduling algorithm

  1. #include
    #include
    #include
    void main()
    {
    char p[10][5];
    int tot=0,wt[10],i,n;
    float avg=0;
    clrscr();
    printf(“enter no of processes:”);
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    {
    printf("enter process%d name:\n",i+1);
    scanf("%s",&p[i]);
    printf("enter process time");
    scanf("%d",&pt[i]);
    }

    wt[0]=0;
    for(i=1;i<n;i++)
    {
    wt[i]=wt[i-1]+et[i-1];
    tot=tot+wt[i];
    }
    avg=(float)tot/n;
    printf("p_name\t P_time\t w_time\n");
    for(i=0;i<n;i++)
    printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
    printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
    getch();
    }

  2. My name is Piter Jankovich. oOnly want to tell, that your blog is really cool
    And want to ask you: is this blog your hobby?
    P.S. Sorry for my bad english

  3. program is nice……….
    but et[] should be replaced by pt[] in the line 23 and 29.

  4. Hi friends :
    I chaneged this program a little,
    It’s correct :

    include

    void main()

    {

    char p[10][5];

    int tot=0,wt[10],pt[10],z,n,i;

    float avg=0;

    printf(“\nenter number of process : “);

    scanf(“%d”,&n);

    for(i=0;i<n;i++)

    {

    printf("\nenter process %d name : ",i+1);

    scanf("%s",&p[i]);

    printf("enter process time : ");

    scanf("%d",&pt[i]);

    }

    wt[0]=0;

    for (i=1;i<n;i++)

    {

    wt[i]=wt[i-1]+pt[i-1];

    tot=tot+wt[i];

    }

    avg=(float)tot/n;

    printf("\np-name\tp-time\tw-time \n");

    for (i=0;i<n;i++)

    printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]);

    printf("\n total waiting time : %d \n avg wating time : %f \n\n ",tot ,avg);

    }

  5. //A program to FCFS

    #include
    #include
    main()
    {
    int p[10],wt[10],bt[10],tat[10],ttat=0,twt=0,i,j,temp,n;
    float awt,atat;
    clrscr();
    printf(“enter the no. of process=>”);
    scanf(“%d”,&n);
    printf(“enter process=>”);
    for(i=0;i”);
    for(i=0;i<n;i++)
    {
    scanf("%d",&bt[i]);
    }
    wt[0]=0;
    for(i=1;i<n;i++)
    {
    wt[i]=wt[i-1]+bt[i-1];
    twt=twt+wt[i];
    }
    for(i=0;i<n;i++)
    {
    tat[i]=wt[i]+bt[i];
    ttat=ttat+tat[i];
    }
    awt=(float)twt/n;
    atat=(float)ttat/n;
    printf("p_number\t P_bt\t p_wt\t p_tat\n");
    for(i=0;i<n;i++)
    printf("%d \t\t %d\t %d\t %d\n",p[i],bt[i],wt[i],tat[i]);
    printf("total waiting time=%d\n avg waiting time=%f",twt,awt);
    printf("\ntotal turnedaroundtime=%d\n avg turnedaround time=%f",ttat,atat);
    getch();
    }

  6. #include
    using namespace std;
    int main()
    {
    int k,p,b,wt=0,total;
    cout<>p;
    for(k=1;k<=p;k++)
    {
    cout<>b;
    total=wt+b;
    cout<<"\nprocess="<<k;
    cout<<"\nburst time="<<b;
    cout<<"\nwaiting time="<<wt;
    cout<<"\nturn around time="<<total;
    wt=wt+b;
    total=wt+b;
    }
    return 0;
    }

  7. #include
    #include
    #include
    void main()
    {
    char p[10][5];
    int tot=0,wt[10],i,n;
    float avg=0;
    clrscr();
    printf(“enter no of processes:”);
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    {
    printf("enter process%d name:\n",i+1);
    scanf("%s",&p[i]);
    printf("enter process time");
    scanf("%d",&pt[i]);
    }

    wt[0]=0;
    for(i=1;i<n;i++)
    {
    wt[i]=wt[i-1]+et[i-1];
    tot=tot+wt[i];
    }
    avg=(float)tot/n;
    printf("p_name\t P_time\t w_time\n");
    for(i=0;i<n;i++)
    printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
    printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
    getch();
    }

  8. Can you help me with Last Come, First Served (LCFS) or Last In, First Out (LIFO)
    C program codes? Please. Many Thanks! 🙂

  9. hgafgsdrwteyyjhwhsjs jjshhsgd…………….??????????????”””””””””””

  10. How can I write and run a FCFS algorithm using C++ knowing that these are the input info:

    Process ,burst time , waiting time

    (p1=burst 24 , wt 0)

    (p2=burst 15 = wt 24)

    (p3=burst 27, wt 39)

    (p4=burst 16, wt 66)

    (p5=burst 16, wt 82)

    Compute average time of waiting time for all processes
    Compute average time of turnaround time for all processes

    turn in your program to compute both time waiting time and turnaround time.
    The project at end will compute the average of both times to find best algorithm

    help me please ..

  11. Tried the same logic as shown.. but the problem arises with the total waiting time as well as average waiting time…

    they appear to be 0 in both the cases..

    Help me !! 🙁

  12. neelu ennalu panralu…! poilu aduthalu semlu vaalu….
    neeelu indhalu collegelu continuelu pannalu mudiyathulu.. neelu veralu collgelu paarulu…

  13. endha saarae party la enna kalichuu..
    Saarae nyaan naan kalichuu..
    pachae neenga kalichadhum ariyum, enna sapadu kalichuu
    adhaan saarae naan thaan kalichuu..
    hehehehehhhehee ariyum saarae nyan vilayatu ku paranchuu..
    endha aayi saarae..
    Comedy paranchuu…
    (apdiyae serupala aranchuu…)

  14. the code is wrong because
    ” et ” is not declare instead of it replace “et ” to “pt “

  15. the code is wrong because
    ” et ” is not declare instead of it replace “et ” to “pt “
    and
    instead of char p[10][10]
    write p[10]
    ………………………………………………. 🙂

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in