#include<stdio.h>
#include<conio.h>
int temp,temp1,burst[10],arrival[10],waiting[10];
int i,j,num;
float Awt,Tat;
char pname[20][20];
void inputdata();
void fcfs();
void calculatedata();
void inputdata()
{
printf("\n Enter the Number of processes:\n Enter Your Choice:");
scanf("%d",&num);
printf("\n Enter Info Of Each Process:");
for(i=1;i<=num;i++)
{
fflush(stdin);
printf("\n Enter the name of process:");
scanf("%[^\n]s",pname[i]);
printf("\n Enter the Burst time for process %s=",pname[i]);
scanf("%d",&burst[i]);
printf("\n Enter the Arrival time for process %s=",pname[i]);
scanf("%d",&arrival[i]);
}
}
void calculatedata()
{
waiting[1]=0;
int Ttt=0; Att=0;
for(i=2;i<=num;i++)
{
waiting[i]=(waiting[i-1]+burst[i-1]);
}
for(i=1;i<=num;i++)
{
Ttt=Ttt+(waiting[i]-arrival[i]);
Att=Att+((waiting[i]+burst[i])-arrival[i]);
}
Awt=float(Att)/num;
Tat=float(Ttt)/num;
printf("\n\t\t Hence the average waiting time is=%3.2f",Awt);
printf("\n\t\t Hence the average turn arround time is=%3.2f",Tat);
}
void fcfs()
{
for(i=1;i<=num;i++)
{
for(j=i+1;j<=num;j++)
{
if(arrival[i]>arrival[j])
{
temp=arrival[i];
temp1=burst[i];
arrival[i]=arrival[j];
burst[i]=burst[j];
arrival[j]=temp;
burst[j]=temp1;
}
}
}
calculatedata();
}
int main()
{
printf("\n\t\t *** Welcome to first come first serve algorithm ***");
printf("\n\n Enter Data:");
inputdata();
fcfs();
getch();
return 0;
}
Gurpreet Singh
No comments:
Post a Comment