I have this program:
int main(){
double x=2;
cout << sqrt(x);
}
I would like to show the result as accurately as possible. Thanks!
I have this program:
int main(){
double x=2;
cout << sqrt(x);
}
I would like to show the result as accurately as possible. Thanks!
Uses setprecision
this way:
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits> // Para ter a máxima precisão
using namespace std;
int main(){
double x=2;
cout << setprecision(numeric_limits<double>::max_digits10) << sqrt(x);
}
You can do this:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double num = sqrt(2);
cout << fixed;
cout.precision(52);
cout << num << endl;
return 0;
}
See running on ideone .