📄 pi.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 + -