Find the missing loop in the following function computes the maximum value contained in an integer array P[] of size n (n>=1).

 The following function computes the maximum value contained in an integer array P[] of size n (n>=1)

                     

int max (int *p,int n)
 {
    int a = 0, b=n-1;
    
    while (__________) 
{
        if (p[a]<= p[b]) 
           {a = a+1;}
        else            
           {b = b-1;}
    }
    return p[a];
}

The missing loop condition is 

  1.  a!=n
  2.  b!=0
  3.  b>(a+1)
  4.  b!=a
1Comment
Sumit Verma @sumitkgp
18 Jul 2017 11:34 pm

Option 4 will be the correct answer. In such questions, take some smaller size array and analyse the program.