Fcfs

PHOTO EMBED

Sat Mar 22 2025 05:53:00 GMT+0000 (Coordinated Universal Time)

Saved by @ccc

#include<stdio.h>
int main(
int pid[10]= (0},bt[10]={0},at[10]={0},tat[10]={0},wt[10]={0},ct[10]=(0};
int n,sum=0,temp,templ,i.j,k,temp2;
float totalTAT=0,total WT=0;
printf("Enter number of processes ");
scanf("d", &n);
printf("Enter the processes detailsin\n");
for(i=0;i<n;i++)
printf("Enter processid");
scanf("@d",&pid[i]);
printf("Arrival time of process[d] ",i+1);
scanf("1/9d", &at[i]);
printf("Burst time of process%d] ",i+1);
scanf("@d",&bt[il);
printf("in");
for (i=0; i<n-1; i++)
for 0=0; j<n-i-1; j++)
if (at[j]>at[+1])
{
// sorting the arrival times
temp = atD];
at|jl = at|j+1];
at[j+1] = temp;
I/ sorting the burst times
templ = btfl:
bti] = bt[j+1];
bt[j+1] = templ;
Il sorting the process numbers
temp2=pid[l;
pid[l=pidD+1];
pidlj+1]=temp2;
}
//calculate completion time of processes
forj=Ojj<n;jt+)
sum+=bbl;
ct[j]+=sum;
}
//calculate turnaround time and waiting times
for(k=0;k<n;kt+)
tat[k]=ct[k]-at[k];
totalTAT+=tat[k];
wt[0]=0;
for(k=0;k<n;k++)
{
wt[k]=0;
forj=0;j<k;j++)
totalWT+=wt[k];
printf("Solution: In\n");
printf("P#t AT\t BT\t CTit TAT\t WTitin\n");
for(i=0;i<n;i++)
{
printf("Pd\t %dIt %dIt %d\t %dit %din",pid[i],at[il,bt[i],ct[il,tat[i],wtfil);
printf("In nAverage Turnaround Time = %fln", totalTAT/n);
printf("nAverage Waiting Time = %fn\n", totalWT/n);
return 0;
}
content_copyCOPY