#include
double fun(int n) {
double rator = 2,nator = 1,mul = 1;
double delta,i = 1;
while(i <= n) {
delta = rator/nator;//2/1*2/3*4/3*4/5*6/5*6/7
printf("rator = %.2lf,nator = %.2lf\n",rator,nator);
mul *= delta;
if((int)i%2) nator += 2;
else rator += 2;
++i;
}
return mul;
}
int main() {
int n,T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
printf("n = %d,mul = %.3lf\n",n,fun(n));
}
return 0;
}
// fun(n)函数内的printf()函数是测试用的,请删除之。
#include
#include
#include
int main(){
float n=1.0;
float s=1;
float i=1.0;
float pi=0;
while(fabs(i)>=1e-6){
pi+=i;
s=-s;
n=n+2;
i=s/n;
}
pi=pi*4;
printf("pi的近似值为%.3f\n",pi);
return 0;
}
檬地心引力八新上半场囱
#include
int main()
{int i,n;
double s=1;
scanf("%d",&n);
for(i=2;i<=n+n;i+=2)
s*=1+1.0/(i*i-1);
printf("%.3lf\n",s);
return 0;
}