Advertisement
salmancreation

OS Lab Class#1

Jul 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j,at[20];
  6.     printf("Enter total number of processes(maximum 20):");
  7.     scanf("%d",&n);
  8.  
  9.     printf("\nEnter Process Arival Time & Burst Time\n");
  10.     for(i=0;i<n;i++)
  11.     {
  12.         printf("P[%d]:",i+1);
  13.         scanf("%d%d",&at[i],&bt[i]);
  14.     }
  15.  
  16.     wt[0]=0;    //waiting time for first process is 0
  17.  
  18.     //calculating waiting time
  19.     for(i=1;i<n;i++)
  20.     {
  21.         wt[i]=0;
  22.         for(j=0;j<i;j++)
  23.             wt[i]+=bt[j];
  24.     }
  25.  
  26.     printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time\tArivel Time");
  27.  
  28.    
  29.     // arival time
  30.     for(i=0;i<n;i++){
  31.         temp = at[i];
  32.         if(at[i]>at[i+1]){
  33.             at[i] = at[i=1];
  34.             at[i+1] = at[i]
  35.         }
  36.     }
  37.    
  38.     //calculating turnaround time
  39.     for(i=0;i<n;i++)
  40.     {
  41.  
  42.         tat[i]=bt[i]+wt[i];
  43.         avwt+=wt[i];
  44.         avtat+=tat[i];
  45.  
  46.        
  47.  
  48.         printf("\nP[%d]\t\t%d\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i],at[i]);
  49.     }
  50.  
  51.     avwt/=i;
  52.     avtat/=i;
  53.     printf("\n\nAverage Waiting Time:%d",avwt);
  54.     printf("\nAverage Turnaround Time:%d",avtat);
  55.     printf("\n\n Thank You Mam \n");
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement