01.
Using this series calculate the value of π
#include
<iostream>
#include<cmath>
using
namespace std;
int
main() {
int k ;
double
val=0.0 , nval;
for(k=1;k<=1000000;k++)
{
val=val+ (
powf(-1,k+1)/(2*k-1) );
}
nval=4*val;
printf(
"Approximate PI=%14.12lf\n ", nval );
printf( "Built
in PI=%14.12lf\n ", M_PI );
return
0;
}
02. Here is the another way of calculating the value of π.
#include<iostream>
02. Here is the another way of calculating the value of π.
#include<iostream>
#include<cmath>
#include<cmath>
using
namespace std;
double val(int n){
int i;
double fal,kal;
fal=6+powf(n+2,2);
for( i=n; i>=1; i-=2 ) {
kal = powf(i,2) / fal;
fal = 6+kal;
}
return
kal;
}
int
main(){
double nval;
nval = 3+val(177); // here odd number
value is needed
printf("
The approximate Pi is =%14.12lf \n", nval);
printf("Difference
=%14.12lf \n", fabs(nval-M_PI) );
return 0;
}
3.0 Here is the another way of calculating the
value of π.
#include<iostream>
#include<cmath>
using namespace
std;
double
val ( int n ) {
int i;
double fal , kal ;
fal=2+ powf( n+2 , 2);
for( i=n; i>=1;
i-=2 ) {
kal = powf(i,2)/fal;
fal = 2+kal;
}
return
kal;
}
int
main() {
double nval , pival;
nval=1+val(1117); // here odd number
value is needed
pival=4/nval;
printf("The
approximate Pi is =%14.12lf \n",pival);
printf("Difference
=%14.12lf \n",fabs(pival-M_PI));
return 0;
}
4.0 Here is the another way of calculating the
value of π. It has
the highest convergence among the other..
#include<iostream>
#include<cmath>
using
namespace std;
double
val( int n ) { // it has the highest convergence
int i;
double fal ,
kal;
fal = (2*n-1) + powf (n, 2);
for( i=n-1; i>=1; i--)
{
kal = powf(i,2) / fal;
fal= (2*i-1) + kal;
}
return
kal;
}
int main() {
double nval,pival;
nval=1+val(115); //
a integer number is needed
pival = 4/nval;
printf("The
approximate Pi is =%14.12lf \n",pival);
printf("Difference
=%14.12lf \n",fabs(pival-M_PI));
return 0;
}