R
R
Ruslan Tilyaev2020-11-24 16:36:32
C++ / C#
Ruslan Tilyaev, 2020-11-24 16:36:32

Is the function program written correctly?

write a program for calculating a function on a given interval with a step of 0.2.
5fbd0d378ef41362432080.png

#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>


using namespace std;

double logic(double x);

int main() {

  for (double x = - M_PI/2; x <= M_PI; x += 0.2) {
    cout << "y = " << logic(x) << endl;
  }

  return 0;
}

double logic(double x) {

  if (x > 2) {
    x = sqrt(log(pow(x,2))-1);
  }
  else if (x >= 0 && x <= 2) {
    x = -2 * pow(x, 3);
  }
  else if (x < 0) {
    x = exp(sin(x));
  }

  return x;
}

5fbd0c509bed4343412456.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-11-24
@galaxy

At least there is an error here:
x = sqrt(log(pow(x,2))-1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question