#include<string.h>
#include<stdio.h>
#include<string.h>
void main()
{
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
printf("\n\n Enter the number of processes: ");
scanf("%d",&n);
printf("\n\n Enter the NAME , BURST TIME and ARRIVAL TIME of the process");
for(i=0;i<n;i++)
{
printf("\n\n NAME : "); scanf("%s",&pname[i]);
printf("\n BURST TIME : "); scanf("%d",&bt[i]);
printf("\n ARRIVAL TIME : "); scanf("%d",&at[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(at[i]>at[j])
{
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}
}
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i]-at[i]);
sbt=sbt+(wt[i+1]-at[i]);
ss=ss+bt[i];
}
avgwt=(float) sum/n;
avgtt=(float)sbt/n;
printf("\n\n Average waiting time = %f",avgwt);
printf("\n\n Average turn-around time = %f",avgtt);
printf("\n\n GANTT CHART\n");
for(i=0;i<n;i++)
printf("|\t%s\t",pname[i]);
printf("|");
printf("\n");
for(i=0;i<n;i++)
printf("%d\t\t",wt[i]);
printf("%d\n",ss);
printf("\n");
}
OUTPUT-->
Enter the number of processes: 4
Enter the NAME , BURST TIME and ARRIVAL TIME of the process NAME : p1
BURST TIME : 4 ARRIVAL TIME : 0
NAME : p2
BURST TIME : 9
ARRIVAL TIME : 2
NAME : p3
BURST TIME : 8
ARRIVAL TIME : 4
NAME : p4
BURST TIME : 3
ARRIVAL TIME : 3
Average waiting time = 6.000000
Average turn-around time = 12.000000
GANTT CHART
| p1 | p2 | p4 | p3
0 4 13 16 24
#include<stdio.h>
#include<string.h>
void main()
{
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
printf("\n\n Enter the number of processes: ");
scanf("%d",&n);
printf("\n\n Enter the NAME , BURST TIME and ARRIVAL TIME of the process");
for(i=0;i<n;i++)
{
printf("\n\n NAME : "); scanf("%s",&pname[i]);
printf("\n BURST TIME : "); scanf("%d",&bt[i]);
printf("\n ARRIVAL TIME : "); scanf("%d",&at[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(at[i]>at[j])
{
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}
}
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i]-at[i]);
sbt=sbt+(wt[i+1]-at[i]);
ss=ss+bt[i];
}
avgwt=(float) sum/n;
avgtt=(float)sbt/n;
printf("\n\n Average waiting time = %f",avgwt);
printf("\n\n Average turn-around time = %f",avgtt);
printf("\n\n GANTT CHART\n");
for(i=0;i<n;i++)
printf("|\t%s\t",pname[i]);
printf("|");
printf("\n");
for(i=0;i<n;i++)
printf("%d\t\t",wt[i]);
printf("%d\n",ss);
printf("\n");
}
OUTPUT-->
Enter the number of processes: 4
Enter the NAME , BURST TIME and ARRIVAL TIME of the process NAME : p1
BURST TIME : 4 ARRIVAL TIME : 0
NAME : p2
BURST TIME : 9
ARRIVAL TIME : 2
NAME : p3
BURST TIME : 8
ARRIVAL TIME : 4
NAME : p4
BURST TIME : 3
ARRIVAL TIME : 3
Average waiting time = 6.000000
Average turn-around time = 12.000000
GANTT CHART
| p1 | p2 | p4 | p3
0 4 13 16 24
No comments:
Post a Comment