采用嵌套调用函数
π/2=(2*2)/(1*3)*(3*3)/(2*4)*(4*4)/(3*5)*.....*[(n+1)]^2/(n*(n+2)),采用嵌套调用函数求π的值#include<stdio.h>
float l(float n)
{
float j(float n);
float k(float n);
float pi,x,y;
pi=2*x/y;
return(pi);
}
float j(float n)
{
int i;
float x=1;
for(i=1;i<n;i++)
{
x=x*(i+1)*(i+1);
}
return(x);
}
float k(float n)
{
float i,y=1;
for(i=1;i<n;i++)
{
y=y*i*(i+2);
}
return(y);
}
main()
{
float l(float n);
int n1;
float PI;
scanf("%d",&n1);
PI=2*l(n1);
printf("%f",PI);
return 0;
}