[php] title

Viewer

  1. <?php 
  2. $var = '<script>
  3.  
  4.     // JavaScript program for implementation of FCFS
  5.    // scheduling
  6.     
  7.     
  8.    // Function to find the waiting time for all
  9.   // processes
  10.     function findWaitingTime(processes,n,bt,wt)
  11.     {
  12.         // waiting time for first process is 0
  13.         wt[0] = 0;
  14.    
  15.         // calculating waiting time
  16.         for (let i = 1; i < n; i++) {
  17.             wt[i] = bt[i - 1] + wt[i - 1];
  18.         }
  19.     }
  20.      
  21.     function findTurnAroundTime(processes,n,bt,wt,tat)
  22.     {
  23.         // calculating turnaround time by adding
  24.         // bt[i] + wt[i]
  25.         for (let i = 0; i < n; i++) {
  26.             tat[i] = bt[i] + wt[i];
  27.         }
  28.     }
  29.      
  30.     function findavgTime(processes,n,bt)
  31.     {
  32.         let wt = new Array(n), tat = new Array(n);
  33.         for(let i=0;i<n;i++)
  34.         {
  35.             wt[i]=0;
  36.             tat[i]=0;
  37.         }
  38.         let total_wt = 0, total_tat = 0;
  39.    
  40.         //Function to find waiting time of all processes
  41.         findWaitingTime(processes, n, bt, wt);
  42.    
  43.         //Function to find turn around time for all processes
  44.         findTurnAroundTime(processes, n, bt, wt, tat);
  45.    
  46.         //Display processes along with all details
  47.         document.write("Processes Burst time Waiting"
  48.                        +" time Turn around time<br>");
  49.    
  50.         // Calculate total waiting time and total turn
  51.         // around time
  52.         for (let i = 0; i < n; i++) {
  53.             total_wt = total_wt + wt[i];
  54.             total_tat = total_tat + tat[i];
  55.             document.write("    ", (i + 1)+" ");
  56.             document.write("     "+  bt[i]+" ");
  57.             document.write("     "+ wt[i]);
  58.             document.write("     "+ tat[i]+"<br>");
  59.         }
  60.         let s = total_wt / n;
  61.         let t = Math.floor(total_tat / n);
  62.         document.write("Average waiting time = "+ s);
  63.         document.write("<br>");
  64.         document.write("Average turn around time = ", t+" ");
  65.     }
  66.      
  67.     let processes=[1,2,3];
  68.     let  n = processes.length;
  69.      
  70.     let burst_time=[10,5,8];
  71.     findavgTime(processes, n, burst_time);
  72.      
  73.     // This code is contributed by rag2127
  74.      
  75. </script>';

Editor

You can edit this paste and save as new: