N Ngọc Trâm New member Sep 17, 2021 #1 What will be the output of the following C++ code? Code: #include <iomanip> #include <iostream> using namespace std; int main() { cout << setprecision(17); double d = 0.1; cout << d << endl; return 0; } A. 0.11 B. 0.10000000000000001 C. 0.100001 D. compile time error
What will be the output of the following C++ code? Code: #include <iomanip> #include <iostream> using namespace std; int main() { cout << setprecision(17); double d = 0.1; cout << d << endl; return 0; } A. 0.11 B. 0.10000000000000001 C. 0.100001 D. compile time error
K Khang Lê New member Sep 17, 2021 #2 Answer: b Explanation: The double had to truncate the approximation due to its limited memory, which resulted in a number that is not exactly 0.1. Output: Code: $ g++ float2.out $ a.out 0.10000000000000001 Upvote 0 Downvote
Answer: b Explanation: The double had to truncate the approximation due to its limited memory, which resulted in a number that is not exactly 0.1. Output: Code: $ g++ float2.out $ a.out 0.10000000000000001