Untitled
unknown
plain_text
a year ago
1.4 kB
5
Indexable
/* * FCFS Scheduling Program in C */ #include <stdio.h> int main() { int pid[15]; int bt[15]; int n; printf("Enter the number of processes: "); scanf("%d",&n); printf("Enter process id of all the processes: "); int i; for( i=0;i<n;i++) { scanf("%d",&pid[i]); } printf("Enter burst time of all the processes: "); for(i=0;i<n;i++) { scanf("%d",&bt[i]); } int wt[n]; wt[0]=0; //for calculating waiting time of each process for(i=1; i<n; i++) { wt[i]= bt[i-1]+ wt[i-1]; } printf("Process ID Burst Time Waiting Time TurnAround Time\n"); float twt=0.0; float tat= 0.0; for(i=0; i<n; i++) { printf("%d\t\t", pid[i]); printf("%d\t\t", bt[i]); printf("%d\t\t", wt[i]); //calculating and printing turnaround time of each process printf("%d\t\t", bt[i]+wt[i]); printf("\n"); //for calculating total waiting time twt += wt[i]; //for calculating total turnaround time tat += (wt[i]+bt[i]); } float att,awt; //for calculating average waiting time awt = twt/n; //for calculating average turnaround time att = tat/n; printf("Avg. waiting time= %f\n",awt); printf("Avg. turnaround time= %f",att); }
Editor is loading...
Leave a Comment