Quando compilo il codice qui sotto, ho avuto questi messaggi di errore:M_PI contrassegnato come identificatore non dichiarato
(Error 1 error C2065: 'M_PI' : undeclared identifier
2 IntelliSense: identifier "M_PI" is undefined)
Che cosa è questo?
#include <iostream>
#include <math.h>
using namespace std;
double my_sqrt1(double n);`enter code here`
int main() {
double k[5] = {-100, -10, -1, 10, 100};
int i;
for (i = 0; i < 5; i++) {
double val = M_PI * pow(10.0, k[i]);
cout << "n: "
<< val
<< "\tmysqrt: "
<< my_sqrt1(val)
<< "\tsqrt: "
<< sqrt(val)
<< endl;
}
return 0;
}
double my_sqrt1(double n) {
int i;
double x = 1;
for (i = 0; i < 10; i++) {
x = (x + n/x)/2;
}
return x;
}
M_PI non è in realtà parte dello standard, quindi non è garantito che sia stato definito in matematica.h – AndyG
E * per favore * ** per favore ** migliorare il titolo. – OJFord