- 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++

9th Aug 2017, 10:31 AM
Arbab Nizamani
Arbab Nizamani - avatar
2 Respostas
+ 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
9th Aug 2017, 12:09 PM
visph
visph - avatar
+ 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 ;)
9th Aug 2017, 11:48 AM
Jojo