Scheduling Program (FCFS), OPERATING SYSTEM in c++
Scheduling Program (FCFS), OPERATING SYSTEM
#include<stdio.h>
int main()
{
int n,i;
float a[20],b[20],c[20];
printf("enter how many processor:");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("enter arrival time of p[%d]:",i+1);
scanf("%f",&a[i]);
printf("enter cpu brust time of p[%d]:",i+1);
scanf("%f",&b[i]);
}
printf("job id \tArrival time \t Cpu brust time\n");
for(i=0;i<n;i++)
{
printf("p[%d]\t %.2f \t\t %.2f\n",i+1,a[i],b[i]);
}
printf("\t\t\t Gantt chart \n");
c[0]=a[0];
for(i=0;i<n;i++)
{
if(i==0)
{
if(c[i]==0)
{
c[i]=a[i];
c[i+1]=b[i]+c[i];
printf("%.0f--p[%d]--%.0f",c[i ],i+1,c[i+1]);
}
else
{
printf("0--ideal--");
c[i]=0;
i--;
}
}
else
{
if(a[i]>c[i])
{
printf("-ideal-");
c[i]=a[i];
printf("%.0f",c[i]);
i--;
}
else
{
c[i+1]=c[i]+b[i];
printf("--p[%d]--%.0f",i+1,c[i +1]);
}
}
}
printf("\n\n");
for(i=0;i<n;i++)
{
printf("waiting time of p[%d]=%.0f\n",i+1,(c[i]-a[i])) ;
}
for(i=0;i<n;i++)
{
printf("turn around time of p[%d]=%.0f\n",i+1,(c[i]-a[i]+b [i]));
}
}
OUTPUT
Post a Comment