SLIDE1

Sunday, December 28, 2014

tính số pi (3.14) - bài tập lập trình c

viết chương trình c, lập trình tính số pi (3.14)

//tính số pi
#include<stdio.h>
#include<conio.h>
#include<math.h>
double pi()
{
double dau,s=1,tong=1;
int n = 1;
while (fabs(s)>0.00001)
{
if (n % 2 == 0) dau = 1; else dau = -1;
s = dau / (2 * n + 1);
tong += s;
n++;
}
return tong*4;
}
void main()
{
printf("%.10lf\n", pi());
}