Answer the question
In order to leave comments, you need to log in
Is the function program written correctly?
write a program for calculating a function on a given interval with a step of 0.2.
#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;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question