Some assignments will be handed in using WebCT. Your MUSS userid is your userid for WebCT as well, and your password is initially set to be your student ID. Please change it!
Something like this works
double dot_product(double *v1, int l1, double *v2, int l2) { if ( (l1==0) || (l2==0) ) return 0; else return (*v1)*(*v2) + dot_product(v1+1, l1-1, v2+1, l2-1); }
I rather like
double dot_product(double *v1, int l1, double *v2, int l2) { return ( (l1==0) || (l2==0) ) ? 0 : (*v1)*(*v2) + dot_product(v1+1, l1-1, v2+1, l2-1); }
A good solution would be
double binary_power(double x, int p) { if (p<0) return 1/binary_power(x,-p); else if (p==0) return 1; else if (p==1) return x; else { int c; c = binary_power(x, p>>1); return c*c*( p%2 == 0 ? 1 : x) ; } }
All those special cases *have* to be there to stop the recursion !!!
The above solution can be expanded into simpler components
double binary_power(double x, int p) { if (p<0) return 1/binary_power(x,-p); else if (p==0) return 1; else if (p==1) return x; else { int c,p_div_2,sqr; p_div_2 = p >> 1; c = binary_power(x, p_div_2); sqr = c*c; if (p%2 == 0) /* p even */ return sqr; else /* p odd */ return sqr*x; } }