⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pi.cpp

📁 利用布丰投针的思想
💻 CPP
字号:
// PI.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
#include "math.h"
#define TIME 65536
#define EDGE 512

int main()
{

	int k=0;
	double a;
	double pi;
    srand((unsigned)time(NULL));

	for(long i=0;i<TIME;i++)
	{
		int x=rand()%EDGE;
	    int y=rand()%EDGE;
		a=sqrt(x*x+y*y);
		if(a<EDGE)k++;
	}
	pi=4*(double)k/TIME;
	printf("PI=%f\n",pi);
    scanf("PI=%f\n",pi);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -