c++计算PI PI/2=1+1/(1*3)+2!/(1*3*5)+3!/(1*3*5*7)+...+n!/(1*3*5*...*(2n+1))#include #include "genlib.h"#include "simpio.h"double fact(int n){int i,m=1;for(i=1;i
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 08:45:21
c++计算PI PI/2=1+1/(1*3)+2!/(1*3*5)+3!/(1*3*5*7)+...+n!/(1*3*5*...*(2n+1))#include #include "genlib.h"#include "simpio.h"double fact(int n){int i,m=1;for(i=1;i
c++计算PI PI/2=1+1/(1*3)+2!/(1*3*5)+3!/(1*3*5*7)+...+n!/(1*3*5*...*(2n+1))
#include
#include "genlib.h"
#include "simpio.h"
double fact(int n)
{int i,m=1;
for(i=1;i
c++计算PI PI/2=1+1/(1*3)+2!/(1*3*5)+3!/(1*3*5*7)+...+n!/(1*3*5*...*(2n+1))#include #include "genlib.h"#include "simpio.h"double fact(int n){int i,m=1;for(i=1;i
#include<stdio.h>
double fact(int n)
{
double m = 1.0;
int i;
for(i = 1; i <= n; i++)
m *= i;
return m;
}
double multi(int n)
{
double m = 1.0;
int i;
for(i = 1; i <= 2 * n + 1; i += 2)
m *= i;
return m;
}
int main()
{
int n;
scanf("%d", &n);
int i, j;
double PI = 1.0;
for(i = 1; i <= n; i++)
{
PI += fact(i) / multi(i);
}
printf("%lf",PI * 2);
return 0;
}