0
good coders i need ur help plz. in my assignment there is this tricky question. write a program to calculate sum of the series: 1 - 1/2 + 1/3 -1/4 +..... -n until the term that is less than 0.0001(1/10000) is reached.
Loops
3 odpowiedzi
0
double sum = 1.0;
for( int n =2; n<=10000; n++)
{
if ( n % 2 == 0 )
sum -= (1.0/n);
else
sum += (1.0/n);
}
Console.WriteLine(sum);
0
thank u boet u real heped me
0
double sum = 0, prevSum = 0;
int n = 1;
do
{
prevSum = sum;
if (n % 2 == 0) sum -= 1.0 / n;
else sum += 1.0 / n;
n++;
}
while (sum - prevSum >= 0.0001);
Console.WriteLine(sum);