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