?? 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 + -