Jan 8, 2017 at 3:19pm UTC
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?
Jan 8, 2017 at 3:27pm UTC
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
Jan 8, 2017 at 3:28pm UTC
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 Jan 8, 2017 at 3:29pm UTC
Jan 8, 2017 at 4:43pm UTC
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?
Jan 8, 2017 at 6:06pm UTC
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 Jan 8, 2017 at 7:09pm UTC