Questions tagged [pi]

π (pi) is a mathematical constant whose value is the ratio of any Euclidean plane circle's circumference to its diameter; this is the same value as the ratio of a circle's area to the square of its radius. It is approximately equal to 3.14159265 in decimal notation. For Raspberry Pi, please tag with "raspberry-pi".

π (pi) is a mathematical constant whose value is the ratio of any Euclidean plane circle's circumference to its diameter; this is the same value as the ratio of a circle's area to the square of its radius. It is approximately equal to 3.14159265 in decimal notation.

For questions related to Raspberry Pi, please use the tag instead.

811 questions
-2
votes
1 answer

Comparing a double to Math.PI (converting double to String)

I'm trying to write a program that compares a double (entered by the user) to the constant Math.PI, after having converted both values to Strings and then comparing them char by char. I'm getting errors but I'm not able to see where I should change…
Caggen
  • 17
  • 3
-2
votes
1 answer

Matlab arrayfun

I do this: A = [pi/2 3*pi/2 3*pi/2 pi]; B = arrayfun(wrapToPi, A); Expecting B: [pi/2 -pi/2 -pi/2 pi] But instead of that, I receive an error message: Not enough input arguments. Error in wrapToPi (line 13) q = (lambda < -pi) | (pi <…
Sergio
  • 844
  • 2
  • 9
  • 26
-2
votes
1 answer

My variable isn't getting valye as expected

Why this code isn't working as expected? When I start debugging proizvod is always on 1, bat it should be 0.75 = 1 - (1/4) and so on. My code is this #include "stdafx.h" #include using namespace std; int _tmain() { int plusminus…
DoktorD96
  • 21
  • 1
  • 7
-2
votes
1 answer

Pi iteration, display the amount of iterations of pi by the users input

The assignment is The following method can be used to approximate the value of Pi: Pi/4 = 1 – (1/3) + (1/5) – (1/7) + (1/9) – (1/11) + … Write a program that allows the user to specify the number of iterations used in this approximation and…
robmdh
  • 1
-2
votes
1 answer

How to calculate circumference with random numbers?

I need to print the circumference with Math.random() * Math.Pi; but i'm doing something wrong or missing something. Each random generated number equals the radius of the circle. My idea was to calculate Pi in the getRandomNumberInRange method but…
Jane Nice
  • 97
  • 1
  • 1
  • 8
-2
votes
1 answer

Cannot determine the estimate of pi

I cannot determine my logic error, Code: import math repeat = "y" factor = [5] def findFactor(): res = factor[0] factor[0] += 2 print(res) return res while (repeat == "y"): tol = float(input("Please enter the…
JPHamlett
  • 365
  • 3
  • 9
-2
votes
1 answer

js Math.PI value not calculating out like it should

Math.sin(75 * (180/3.14)); -> 0.9956310419973837 Math.sin(75 * (180/Math.PI)); -> -0.4927842805101025 The above is copied from js debugger in acrobat. I am not understanding why. The first value (.995....) is correct. Any help/explanations would…
-2
votes
1 answer

Infinite loop on C using while, pi approximation

I'm having some problems with this loop. It's infinite but I dont know what is causing it. This is part of a long code so I'm just posting part of it I'm supposed to use Machin's approximation series for this and it's supposed to have just a .001…
-2
votes
1 answer

Estimating Pi using leibniz in C++

I am using the leibniz method for calculating pi. My program inputs an accuracy number for a calculation of π and then applies the leibniz infinite sum to find an approximate value of π within that accuracy. I am trying to write a c++ while loop…
user2444074
  • 137
  • 3
  • 6
  • 14
-2
votes
2 answers

Approximating Pi

Following is the code I wrote for approximating the value of 103993/33102. The user inputs the precision. Here k is the precision inputted by the user and asd is the value in the form of a string int tot = 4687; int divisor = 33102; StringBuffer…
Abhiroop Sarkar
  • 2,251
  • 1
  • 26
  • 45
-3
votes
2 answers

Why Python code for approximating value of pi not giving me the correct value?

The value of pi can be approximated as =3+4/(2×3×4)−4/(4×5×6)+4/(6×7×8)−4/(8×9×10)+... Notice how it alternates the plus and minus signs. Write a function that receives an integer n and returns the approximated value of pi, with n terms computed in…
thumpy
  • 21
  • 1
-3
votes
1 answer

I get an error. "%ld expects argument of type 'long int', but argument 2 has type 'int'

This is my program: #include #include #include #include #define NPTS 1000000000 void main() { uint64_t i; double a,b,c,pi,dt,mflops; struct timespec tstart,tend; …
-3
votes
2 answers

i need more decimal places for pi calculation

I'm trying to make a Pi calculator in python but I need more decimal places. it would help a lot if someone edited my code and carefully explained what they did. this is the code I'm using. import math d = 0 ans = 0 display = 0 while True: …
-3
votes
1 answer

C rounding double to 6dp

I am using the following code to calculate pi in C but the answer is only being printed to 6dp. code: #include #include long double calc_pi(int terms) { long double result = 0.0F; long double sign = 1.0F; for (int n…
-3
votes
4 answers

How do I use input in def (Python)

I'm a newbie when it comes to coding. I would highly appreciate it if you can help me solving my problem regards to coding. I tried to use input in my def but doesn't work. import random def estimate_pi(n): num_point_circle = 0 …
1 2 3
53
54