Q
Q
QAJunior2021-11-18 06:21:51
C++ / C#
QAJunior, 2021-11-18 06:21:51

Why does the "inf,-nand(inf)" error occur?

Hello, a beginner programmer, I need to make a Taylor series, but I ran into a problem: the console issues inf, -nand (inf) can you help?

here is the code:

#include<iostream>
#include<stdio.h>
#include<math.h>

using namespace std;

int main()
{
  setlocale(LC_CTYPE,"Russian");
  double dx, xn, xk, m, c, F, eps;
  float n;

  printf("Введите xn: "); cin >> xn;
  printf("Введите xk: "); cin >> xk;
  printf("Введите dx: "); cin >> dx;
  printf("Введите eps: "); cin >> eps;

  printf("-------------------------------------------------------\n");
  printf("| x | F | n | math F |\n");
  printf("-------------------------------------------------------\n");

  for (n = 0; xn <= xk; xn += dx)
  {
    c = xn;
    F = c;
    while ((n < 500) && (abs(F) > eps))
    {
      F *= xn * n / (n + 1);
      c += F;
      n++;
    }
    c *= -1;
    m = log(1 - xn);
    printf("| %9.2lf | %12.5f | %9.2ld | %12.5lf |\n", xn, c, n, m);
  }
  printf("-------------------------------------------------------\n");
  printf(" ");
  return 0;
}

and task6195c6c33e7d2382733930.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question