#include<stdio.h>
struct process
{
char name;
int at,bt,ct,tt;
float ntt;
}p[10];
int n;
void sortByArrival()
{
struct process temp;
int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if(p[i].at>p[j].at)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
void main()
{
int i,j,time=0;
char c;
printf("Enter no of processes:");
scanf("%d",&n);
for(i=0,c='A';i<n;i++,c++)
{
p[i].name=c;
printf("\nEnter the arrival time of process%d: ",i+1);
scanf("%d",&p[i].at);
printf("\nEnter the burst time of process%d: ",i+1);
scanf("%d",&p[i].bt);
}
sortByArrival();
printf("\nName\tArrival Time\tBurst Time\tTurnAround Time\t Normalized TT");
for(i=0;i<n;i++)
{
time+=p[i].bt;
p[i].ct=time;
p[i].tt=p[i].ct-p[i].at;
p[i].ntt=((float)p[i].tt/p[i].bt);
printf("\n%c\t\t%d\t\t%d\t\t%d\t\t%f",p[i].name,p[i].at,p[i].bt,p[i].tt,p[i].ntt);
}
}
struct process
{
char name;
int at,bt,ct,tt;
float ntt;
}p[10];
int n;
void sortByArrival()
{
struct process temp;
int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if(p[i].at>p[j].at)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
void main()
{
int i,j,time=0;
char c;
printf("Enter no of processes:");
scanf("%d",&n);
for(i=0,c='A';i<n;i++,c++)
{
p[i].name=c;
printf("\nEnter the arrival time of process%d: ",i+1);
scanf("%d",&p[i].at);
printf("\nEnter the burst time of process%d: ",i+1);
scanf("%d",&p[i].bt);
}
sortByArrival();
printf("\nName\tArrival Time\tBurst Time\tTurnAround Time\t Normalized TT");
for(i=0;i<n;i++)
{
time+=p[i].bt;
p[i].ct=time;
p[i].tt=p[i].ct-p[i].at;
p[i].ntt=((float)p[i].tt/p[i].bt);
printf("\n%c\t\t%d\t\t%d\t\t%d\t\t%f",p[i].name,p[i].at,p[i].bt,p[i].tt,p[i].ntt);
}
}
OUTPUT:
Enter no of processes:5
Enter the arrival time of process1: 0
Enter the burst time of process1: 3
Enter the arrival time of process2: 2
Enter the burst time of process2: 6
Enter the arrival time of process3: 4
Enter the burst time of process3: 4
Enter the arrival time of process4: 6
Enter the burst time of process4: 5
Enter the arrival time of process5: 8
Enter the burst time of process5: 2
Name Arrival Time Burst Time TurnAround Time Normalized TT
A 0 3 3 1.000000
B 2 6 7 1.166667
C 4 4 9 2.250000
D 6 5 12 2.400000
E 8 2 12 6.000000
No comments:
Post a Comment