#include<stdio.h>
main()
{
int b[10],p[10],t[10],w[10],n,i,j,tot=0,tot_turn=0;
float avg;
printf("\n Enter the number of Process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the process no:");
scanf("%d",&p[i]);
printf("\n Enter the burst time:");
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(b[i]>b[j])
{
int temp;
temp=p[i];
p[i]=p[j];
p[j] = temp;
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
w[0] = 0;
t[0] = b[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
t[i] = w[i] + b[i];
}
printf("\n\n Gantt Chart:");
printf("\n\n..........................................");
printf("\n|p%d\t|",p[0]);
for(i=1;i<n;i++)
printf("p%d\t|",p[i]);
printf("\n\n..........................................");
printf("%d",w[0]);
printf("\t%d",t[0]);
for(i=1;i<n;i++)
printf("\t%d",t[i]);
printf("\n\n|");
printf("\n Process \t Burst time \t Waiting time \t Turnaround time");
printf("\n...........\t.............\t...........\t.........\n");
for(i=0;i<n;i++)
{
printf("\n p%d \t %d \t%d \t%d",p[i],b[i],w[i],t[i]);
tot = tot + w[i];
tot_turn = tot_turn + t[i];
}
avg=(float)tot/n;
printf("\n\n The average waiting time is: %f",avg);
avg = (float)tot_turn/n;
printf("\n\n The average turn around time is %f",avg);
}
main()
{
int b[10],p[10],t[10],w[10],n,i,j,tot=0,tot_turn=0;
float avg;
printf("\n Enter the number of Process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the process no:");
scanf("%d",&p[i]);
printf("\n Enter the burst time:");
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(b[i]>b[j])
{
int temp;
temp=p[i];
p[i]=p[j];
p[j] = temp;
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
w[0] = 0;
t[0] = b[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
t[i] = w[i] + b[i];
}
printf("\n\n Gantt Chart:");
printf("\n\n..........................................");
printf("\n|p%d\t|",p[0]);
for(i=1;i<n;i++)
printf("p%d\t|",p[i]);
printf("\n\n..........................................");
printf("%d",w[0]);
printf("\t%d",t[0]);
for(i=1;i<n;i++)
printf("\t%d",t[i]);
printf("\n\n|");
printf("\n Process \t Burst time \t Waiting time \t Turnaround time");
printf("\n...........\t.............\t...........\t.........\n");
for(i=0;i<n;i++)
{
printf("\n p%d \t %d \t%d \t%d",p[i],b[i],w[i],t[i]);
tot = tot + w[i];
tot_turn = tot_turn + t[i];
}
avg=(float)tot/n;
printf("\n\n The average waiting time is: %f",avg);
avg = (float)tot_turn/n;
printf("\n\n The average turn around time is %f",avg);
}
1 comment:
WTH, this is code, not algorithm -_-
Post a Comment