By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,515 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,515 IT Pros & Developers. It's quick & easy.

partial sum

P: n/a
pgn
Hi,
I have to write a program which will be adding 10 to the power of n
digits 10 to the power of -n (10^n digits 10^-n) by adding partial sum.
For example: for n=6 it will be 1000 times by 1000 or 10000 times by
100).
Any idea?

Nov 9 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pgn wrote:
Hi,
I have to write a program which will be adding 10 to the power of n
digits 10 to the power of -n (10^n digits 10^-n) by adding partial sum.
For example: for n=6 it will be 1000 times by 1000 or 10000 times by
100).
Any idea?


Yes, but we won't do your homework for you
(http://www.parashift.com/c++-faq-lit....html#faq-5.2). Post
your code, and we can give you some advice.

Cheers! --M

Nov 9 '05 #2

P: n/a
pgn
ok, but its not my homework, i'm just learnig programming from a book,
and there is an example like this without solution.
In "regular" loop i have something like this:
double how_many_digits = pow(10, n);
double digits = pow(10, -n);
for(int i=0; i<=how_many_digits; i++)
{
result = result + digits;
}

but now i don't know how to write using adding partila sum. I have try
something like this, but its only valid for even n
double how_many_digits = pow(10, n/2);
double how_many_times = pow(10, n/2);
double digits = pow(10, -n);
for(int i=0; i<=how_many_times; i++)
{
for(int j=1; j<=how_many_digits; j++)
{
result = result + digits;
}
}

I'm not sure is it correctly (for even digits ofcourse).

Nov 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.