Find the maximum GCD of a number with respect to all the values in an array for competitive programming
gcdn[] is unused.  
if n==0, you access a non-existent array element, and even if it isn't, you do the GCD with a[0] twice.  
gcd() is called before it is declared, which is bad style and can mess up optimization.  
you might think about whether the M or arr[] elements are likely to be larger.  The order you pass values to gcd() can reduce by one loop if you guess right.
The tail recursion on gcd() should be OK as long as you optimize.