partial sum

P

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?
 
P

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top