Friday, 8 May 2015

First Come First Serve Algorithm Implementation Using C

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

main()
{
int Count=0,i=0,ID[100],Time[100],Wait=0,WaitTime=0,Turn=0;
clrscr();
printf("\n Enter No Of Proceses   ");
scanf("%d",&Count);

for(i=0;i<Count;i++)
{
printf("\n Enter No %d) Process ID   :",i+1);
scanf("%d",&ID[i]);
printf("\n Enter Service Time        :");
scanf("%d",&Time[i]);
}

printf("\n ID     Service     Wait    Total");

for(i=0;i<Count;i++)
{
WaitTime+=Wait;
printf("\n %d        %d        %d        %d",ID[i],Time[i],Wait,Wait+Time[i]);
Wait=Time[i]+Wait;
Turn+=Wait;
}
printf("\n Average Waiting Time   :%.2f",floor((float)WaitTime/(float)Count));
printf("\n Average Turnaround Time  :%.2f",floor((float)Turn/(float)Count));
getch();
}


Output:

 Enter No Of Proceses   3
 Enter No 1) Process ID   :100
 Enter Service Time        :24
 Enter No 2) Process ID   :101
 Enter Service Time        :3
 Enter No 3) Process ID   :102
 Enter Service Time        :3

 ID     Service     Wait    Total
 100        24        0        24
 101        3        24        27
 102        3        27        30

 Average Waiting Time   :17.00

 Average Turnaround Time  :27.00

No comments:

Post a Comment