D
D
DartNyan2015-11-23 22:37:22
C++ / C#
DartNyan, 2015-11-23 22:37:22

Should it be?

Hello.
A simple task, but somehow something ..

spoiler
lYr0bBhLj0c.jpg

The left side should match the right side.
Instead of infinity, you can take 100.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    double x;
    double resultForLN = 0, resultForSum = 0;

    printf("Enter X : ");
    scanf("%g",&x);

        resultForLN = log( (1.0 + x) / (1.0 - x) );
    printf("%g",resultForLN); // Левый результат

    for (int k = 1; k < 100; k++)
        resultForSum += pow(x, (2.0 * k - 1.0)) / (2.0 * k - 1.0);
    printf("\n%g",resultForSum * 2.0); // Правый результат
}

Fa3Zz-24S-c.jpg

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mercury13, 2015-11-23
@DartNyan

You have an error in scanf.
%lgworks too - at least on MinGW.
Little is known, but scanf has a slightly different substitution format than printf.

M
MiiNiPaa, 2015-11-23
@MiiNiPaa

Forget about float, always use double by default.
You calculate x^197 / 197 at the end. Even with x = 2, this will not fit into the float.

M
mad_god, 2015-11-23
@mad_god

Works great on numbers less than unity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question