2
This is the same question as Solve the CodeSprint4 Leibniz code golf challenge in Python in 66 characters. The variation is that I'm a C programmer. My code for the above question is:
#include <math.h>
main(){
int i,t,p;
scanf("%d",&t);
while(t--)
{
double s=1;
scanf("%d",&p);
for(i=1;i<p;++i)
s+=pow(-1,i)/(2*i+1);
printf("%.12lf\n",s);
}
}
Now I just need to know the places where I could reduce my code length.
You missed
#include<stdio.h>
– Spikatrix – 2015-03-01T10:21:35.270Actually, you don't need neither of the two
#include
@CoolGuy. Most C compilers will complain but compile nevertheless. – Stefano Sanfilippo – 2015-03-02T21:03:55.480Please include a specification of the requirements in the body of the question. When the link's dead, it's impossible to know what inputs are expected and what output to produce, other than by grokking the code. – Toby Speight – 2018-07-20T08:55:38.600
I'm guessing that the objective is to compute the Leibniz formula for π (1 - 1/3 + 1/5 - 1/7 +...) to
– Toby Speight – 2018-07-20T09:07:03.177p
terms,t
times - is that right?