SJF
Sat Mar 22 2025 07:47:20 GMT+0000 (Coordinated Universal Time)
Saved by
@Sahithi
#include<stdio.h>
#include<conio.h>
#define max 30
void main()
{
Int i,j,n,t,p[max],bt[max],wt[max],tat[max],Total_wt=0,Total_tat=0;
float awt=0,atat=0;
printf("Enter the number of processes\n");
scanf("%d",&n);
//Enter the processes according to their arrival times
for(i=0;i<n;i++)
{
printf("Enter the process number\n");
scanf("%d",&p[i]);
printf("Enter the burst time of the process\n");
scanf("%d",&bt[i]);
}
//Apply the bubble sort technique to sort the processes according to their burst times
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(bt[j]>bt[j+1])
{
// Sort according to the burst times
t=bt[j];
bt[j]=bt[j+1];
bt[j+1]=t;
//Sorting Process Numbers
t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
printf("Process\t Burst Time\t Waiting Time\t Turn Around Time\n");
for(i=0;i<n;i++)
{
wt[i]=0;
tat[i]=0;
for(j=0;j<i;j++)
wt[i]=wt[i]+bt[j];
tat[i]=wt[i]+bt[i];
Total_wt=Total_wt +wt[i];
Total_tat=Total_tat+tat[i];
printf("%d\t %d\t\t %d\t\t %d\n",p[i],bt[i],wt[i],tat[i]);
}
awt=(float)Total_wt /n;
atat=(float)Total_tat /n;
printf("The average waiting time = %f\n",awt);
printf("The average turn aroud time = %f\n",atat);
}
content_copyCOPY
Comments