csenotes12

processes using a Gantt chart.

Apr 9th, 2019
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4.  {
  5.    int x,n,p[10],pp[10],bt[10],w[10],t[10],awt,atat,i,at[10],tq;
  6.  
  7.    //n is number of process
  8.    //p is process
  9.    //pp is process priority
  10.    //bt is process burst time
  11.    //w is wait time
  12.    // t is turnaround time
  13.    //awt is average waiting time
  14.    //atat is average turnaround time
  15.    //at is arrival time
  16.    //tq is time qunatum
  17.  
  18.  
  19.    printf("Enter the number of process : ");
  20.    scanf("%d",&n);
  21.    printf("Enter time quantum");
  22.    scanf("%d",&tq);
  23.    printf("\n\t Enter burst time : time priorities : Arrival time  \n");
  24.  
  25.    for(i=0;i<n;i++)
  26.     {
  27.       //cout<<"\nProcess["<<i+1<<"]:";
  28.       printf("\n Process %d ",i+1);
  29.       //cin>>bt[i]>>pp[i]>>at[i];
  30.       scanf("%d %d %d",&bt[i],&pp[i],&at[i]);
  31.       p[i]=i+1;
  32.     }
  33.  
  34. //sorting on the basis of priority
  35. int j;
  36.   for(i=0;i<n-1;i++)
  37.    {
  38.      for(j=i+1;j<n;j++)
  39.      {
  40.        if(pp[i]<pp[j])
  41.        {
  42.      x=pp[i];
  43.      pp[i]=pp[j];
  44.      pp[j]=x;
  45.      x=bt[i];
  46.      bt[i]=bt[j];
  47.      bt[j]=x;
  48.      x=p[i];
  49.      p[i]=p[j];
  50.      p[j]=x;
  51.       }
  52.       //gc[i]=p[j];
  53.    }
  54. }
  55. w[0]=0;
  56. awt=0;
  57. t[0]=bt[0];
  58. atat=t[0];
  59. for(i=1;i<n;i++)
  60.  {
  61.     if(tq<n || tq>n) {
  62.      
  63.    w[i]=t[i-1];
  64.    awt+=w[i];
  65.    t[i]=w[i]+bt[i];
  66.    atat+=t[i];
  67.      }
  68.  }
  69.  
  70.  //Gantt chrat
  71.  printf("\n");
  72.  printf("Gantt chart\n");
  73.  for(i=0;i<n;i++)
  74.  {
  75.     printf("P %d ",p[i]);
  76.  }
  77. //Displaying the process
  78.  
  79. printf("\n\nProcess \t Burst Time \t Wait Time \t Turn Around Time   Priority \tArrival time \n");
  80. for(i=0;i<n;i++){
  81. printf("\n  %d",p[i]); printf("\t\t %d",bt[i]); printf("\t\t %d",w[i]); printf("\t\t %d",t[i]); printf("\t\t %d",pp[i]); printf("\t\t %d",at[i]);
  82.  
  83. }
  84. awt/=n;
  85. atat/=n;
  86. printf("\n Average Wait Time : %d ",awt);
  87. printf("\n Average Turn Around Time : %d",atat);
  88. getch();
  89. }
Add Comment
Please, Sign In to add comment