C program to implement the FCFS(FIRST COME FIRST SERVE) scheduling algorithm

 https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJfShSmc4uzJ32B_Cnh6KDE7EeSGsUpqwnmXpsZMSrMSp0wjgo7gGWZu_JIDHC_zUiWwWkPBhm3Pz_vS0k-tjHPGbd4J7sxNkEVv5q-YbMtId0PtXLQqi2n_k4Dee10jKN6F-IOkz4Wqgg/s1600/c+and+c%252B%252B+meansofmine.jpg




AIM

To write a program to implement the FCFS scheduling algorithm

ALGORITHM

1. Start the process

2. Declare the array size

3. Get the number of processes to be inserted

4. Get the value

5. Start with the first process from it’s initial position let other process to be in queue

6. Calculate the total number of burst time

7.  Display the values

8. Stop the process

 
PROGRAM:

#include<stdio.h>
main()
{
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");
            scanf("%d",&n);
printf("enter the burst times");
            for(i=0;i<n;i++)
                scanf("%d",&b[i]);
    printf("\nenter the arrival times");
            for(i=0;i<n;i++)
                scanf("%d",&a[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\twaiting time\tturn arround time\n");
            for(i=0;i<n;i++)
            {
                        printf("\tp%d\t\t%d\t\t%d\n",i,w[i],t[i]);
            }
printf("the average waiting time is %f\n",awt);
printf("the average turn around time is %f\n",att);
}
 
OUTPUT:
enter the number of process 4
enter the burst times
4  9  8  3
enter the arrival times
0  2  4  3
        process        waiting time     turn arround time
            p0                       0                          4
            p1                       2                         11
            p2                       9                         17
            p3                      18                        21
the average waiting time is 7.250000
the average turn around time is 13.250000

8 comments:

janakiraman said...

hi frnds ple corect the folowing program
#include
{
int p1,p2,p3,p4;
int p[1]=2.p[2]=10,p[3]=14,p[4]=16;
printf("the cpu burset time is =",p[1],p[2],p[3],p[4]);
scanf("%d",&p[1]&,p[2]&,p[3]&,p[4]);
for(i=1;i<=4;i++)
{
int x[0],p[0]=0;
waiting timex[i]=x[i-1]+p[i-1];
}
printf("waiting time of cpu is=",&x1);
printf("waiting time of cpu is=",&x2);
printf("waiting time of cpu is=",&x3);
printf("waiting time of cpu is=",&x4);
average time is a=x[4]/4;
printf("average time is=",&a);
}

Anonymous said...

scanf("%d%d%d%d",&p[1]&,p[2]&,p[3]&,p[4]);

Anonymous said...

scanf(%d)

Anonymous said...

Mohsin
#include is missing according to my point of view.ok

Unknown said...

what is g[10] in this code plz reply soon

Anonymous said...

where is main() function??
What is the purpose of using printf statement at line 5??

Unknown said...

working but not displaying turn around time of process....

Unknown said...

working but see this also after some editing in this program
#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();
}

output:
enter the arrival times:
0 1 2
enter the burst times:
2 2 20

process A_time B_time W_time TA_time
p0 0 2 0 2
p1 1 2 1 3
p2 2 20 2 22
the average waiting time is : 1.000000
the average turn around time is : 9.000000

and the output is correct i have solved it

Post a Comment