Why const double pi is used? Why cant i put const pi=3.1 instead of 3.14 ?? Pls answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why const double pi is used? Why cant i put const pi=3.1 instead of 3.14 ?? Pls answer

28th Mar 2020, 4:42 AM
alpha khag
2 Answers
+ 3
You can choose to not declare the variable and write 3.142 in place of the variable, but writiing pi in place of the literal value makes your code better in terms of readability. From a reader's perspective, semantics matter.
28th Mar 2020, 5:49 AM
Fermi
Fermi - avatar
+ 1
hi, because py is a very special number (never ended) and use for lot of important maths equations. So, we need something more precise but not too long to kill your self when you calculate. try to calculate perimeter or surface of a circle with 3.1 and after with 3.14 and after with 3.2, look the difference.
28th Mar 2020, 4:53 AM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar