- 1
Can i print pi as non terminating in C++ with all of its decimal digits .?
i want to know the syntax or method how to write that code in c++
2 ответов
+ 4
Print all decimal digits of an infinite decimal digits number isn't possible ^^
You can maybe use algorithm to calculate it and display them one next one, but this would never end, whatever the computer and algorithm accuracy/performance ;P
[edit]
And don't double post your question:
https://www.sololearn.com/Discuss/606233/?ref=app
+ 2
You can use methods from 'iomanip':
setprecision(int);
or
setw(int);
setprecision(int) acts on the numbers after the decimal point:
cout<<setprecision(2)<<10.0/3.0;//outputs 3.33
setw(int) acts on significant numbers :
cout<<setw(6)<<10.0/3.0;//outputs 3.33333
Be carreful, once setw(int) or setprecision(int) modified, all out streams are concerned:
cout<<setprecision(3);
cout<<10.0/3.0;//outputs 3.333
cout<<6.0;//outputs 6.000
I don't think you can display all Pi's decimals because of memory...
But using these methods, you can have a big precision.
My answer is a bit complex, ask if you don't understand ;)