Sum of the series?

hello,

i am trying to figure out this program, how do i go about this?

sum = a+1/b*1 + a+2/b*2 + a+3/b*3 +...+ a+n/b*n

Rewrite the program for a=1,b=2,n=10?
There is a possible ambiguity in the question.

Does this a+n/b*n mean

a+(n/b)*n

or

a+n/(b*n)

The first simplifies to a+n2/b

while the second simplifies to a+1/b

Are you sure about your denominator, it's b times n and not b to the power of n? Otherwise the result is trivial, for non-zero n:
1
2
(a + 1/b) + (a + 1/b) + ... + (a + 1/b) //n times 
= (a + 1/b) * n 


edit: please put all expressions within parentheses in your reply so that there is no ambiguity re the query
Last edited on
Void main ()
{
int a=1, b=2, n=10;
Float sum =0;
Int i=0;
Do {
Sum= (a+i)/(b*i);
I++;
} while (i <=n);
Cout << sum;
}



I think I got it?
So it was a different ambiguity?
 
    a+n/b*n 
should actually be
 
    (a+n)/(b*n)
?

Not sure the above code is correct. Aside from the invalid use of void main() which won't compile (it isn't allowed in ISO standard C++), and the capitalisation which suggests the code hasn't been tested, there is the starting value of variable i which is zero, shouldn't it be 1?




And a fair bit of integer division

And the fact nothing is actually added to sum : it just ends up as the last term in the sequence.

And (1/b) could have been taken out as a factor.

...

Peculiar problem. Appears to come from
http://scisweb.ulster.ac.uk/~siddique/OOP/Extra-Tutorial-Exam-16.doc
and the model answers in there are a bit worrying.
Last edited on
Topic archived. No new replies allowed.