#Input an integer n, and output the estimated π values of the series at the nth item.

19 messages · Page 1 of 1 (latest)

peak forumBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

vivid kiln
#

Which part are you stuck on?

pseudo sonnet
#

#include <iostream>
using namespace std;
int main() {
int num;
int a,a2;
int b=1;
int c=1;
cout<< "Input a number: ";
cin >> num;
for (int num2=1;num2<=num;num2++){
c*=num2;
if (a%2==1){
a2=a+b;
}
else {
a2=a-b;
}
}
cout << c;

return 0;

}

#

the math part

#

i will need to add 2n-1 into the loop right

vivid kiln
#

Your naming is confusing. Where is your pi variable? What are a and a2 and b and c?

#

I understand num.

#

Apparently c is your pi because you print it out. The problem is that c is an int which means integer which means no comma and no digits after the comma which is not suitable to hold pi.

pseudo sonnet
#

i will need to use float

#

?

#

to hold pi

vivid kiln
#

Better double

#

I don't understand c*=num2; at all. Where did that multiplication come from? Both formulas use sums only, you never multiply your pi estimate with anything.

pseudo sonnet
#

this is about using for to write down the math equation

vivid kiln
#

Yes

#

Have you decided which formula to use?

pseudo sonnet
#

leibniz

vivid kiln
#

Ok. I see a 4 in every term and then it gets divided by something. Where is the 4 in your code?

tacit garden
#

Holy cow Toeger going deep