程序核心——while语句

程序

#include<stdio.h>
#include<math.h>
int main()
{
	int denominator,flag;
	double item,pi;
	
	flag=1;
	denominator=1;
	item=1.0;
	pi=0;
	while(fabs(item)>=0.0001)
	{
		item=flag*1.0/denominator;
		pi=pi+item;
		flag=-flag; 
		denominator+=2;
	}
	pi=pi*4;
	printf("*pi=%.4f\n",pi); 
 } 

结果

*pi=3.1418

--------------------------------
Process exited after 0.7024 seconds with return value 0
请按任意键继续. . .

分析

重点:循环语句while

相关文章:

  • 2021-05-18
  • 2022-12-23
  • 2021-12-10
  • 2022-01-22
  • 2021-08-12
  • 2021-11-03
  • 2022-12-23
  • 2021-05-13
猜你喜欢
  • 2022-03-02
  • 2022-12-23
  • 2021-04-01
  • 2021-05-20
  • 2021-12-11
  • 2021-10-07
相关资源
相似解决方案