Currently I am trying to implement this formula pi = n*(sin(180/n)); in xcode. But just writing it like this gives me huge numbers like -12425553 or 23082083. How can I fix it??
I used int n; double pi;.
Update:
I tried using M_PI/180 to convert to degrees but it still doesn't work. Any suggestions??
pi = n*sin((180/n) * (M_PI/180));
By the way I removed the asterisks!!
There are three problems with your code:
sin takes degrees (it takes radians)sin indeed took degrees, which it does not, you should have used 180.0 in place of 180)To convert degrees to radians, use this formula:
(degrees*M_PI)/180.0
Most likely the '180/n' part is dividing integers. Try:
sin(180.0/n);
Edit as @sosborn correctly pointed, you are doing arithmetic among 'pointer to int', not ints themselves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With