Posts

Search

Homework

QUESTION DESCRIPTION

Student Bharath is assigned with several homework from various subject by his Teachers. He is also insisted to complete the homework based on their ordering sequence. You are asked to calculate average turnaround time and average waiting time.
INPUT :
Line 1 : No of Process
Line 2 : Burst time of each process

TEST CASE 1

INPUT
5
2 3 5 12 3
OUTPUT
Average Waiting Time:7
Average Turnaround Time:12

TEST CASE 2

INPUT
4
5 7 8 9
OUTPUT
Average Waiting Time:9
Average Turnaround Time:16

Code :

#include <iostream>
using namespace std;
int main() 
{
 int size;
   cin>>size;
   int burst[size],wait[size],turna[size],ta=0,avg=0;
   turna[0]=0;
   for(int i=0;i<size;i++)
    {
       cin>>burst[i];
    }
   for(int i=1;i<=size;i++)
    {
     turna[i]=turna[i-1]+burst[i-1];
       ta+=turna[i];
    }
   wait[0]=0;
   for(int i=1;i<size;i++)
    {
     wait[i]=wait[i-1]+burst[i-1];
       avg+=wait[i];
    }
   cout<<"Average Waiting Time:"<<avg/size;
   cout<<"\nAverage Turnaround Time:"<<ta/size;
 return 0;
}