Advertisement
MHSS

OS-FCFS

Aug 21st, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.     int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
  6.     clrscr();
  7.     printf("\n----FCFS-----\n");
  8.     printf("\nEnter total number of processes:");
  9.     scanf("%d",&n);
  10.  
  11.     printf("\nEnter Process Burst Time\n");
  12.     for(i=0;i<n;i++)
  13.     {
  14.     printf("P[%d]:",i+1);
  15.     scanf("%d",&bt[i]);
  16.     }
  17.  
  18.     wt[0]=0;    //wt for first process is 0
  19.  
  20.     //calculating waiting time
  21.     for(i=1;i<n;i++)
  22.     {
  23.     wt[i]=0;
  24.     for(j=0;j<i;j++)
  25.         wt[i]+=bt[j];
  26.     }
  27.  
  28.     printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
  29.  
  30.     //calculating turnaround time
  31.     for(i=0;i<n;i++)
  32.     {
  33.     tat[i]=bt[i]+wt[i];
  34.     avwt+=wt[i];
  35.     avtat+=tat[i];
  36.     printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
  37.     }
  38.  
  39.     avwt/=i;
  40.     avtat/=i;
  41.  
  42.     printf("\n\nAverage Waiting Time:%d",avwt);
  43.     printf("\nAverage Turnaround Time:%d",avtat);
  44.  
  45.     getch();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement