This message was edited by gaetano at 2004-5-11 2:46:35
Hi!
After a few corrections this algorithm works at least, but some questions just won't be answered in my considerations. So please help me:
- What advantages offers this algorithm which my don't?
- Why do you take an float as the second parameter? It's obviously unnecessary as you're always checking against an integer ...
And some other Comments I'd like to do:
- What about calculating the n-th power of 1? It's always 1! At last the whole term with the power is useless, because the 1 should be positive and _not_ negative.
- All these unnecessary calculations have no effect and prolong the calculation time!
Your corrected code:
double
sum(int beg,float n)
{
if(n==0)
return -1;
if(beg>n)
return 0;
else
return (1/(double) beg + pow (1, beg+1) * sum (++beg, n));
}
My code:
double
calc1_x (int n)
{
if (n == 1)
return 1;
return 1.0/n + calc1_x (n - 1);
}