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.
19 messages · Page 1 of 1 (latest)
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.
Which part are you stuck on?
#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
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.
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.
this is about using for to write down the math equation
leibniz
Ok. I see a 4 in every term and then it gets divided by something. Where is the 4 in your code?
Holy cow Toeger going deep