Monte Carlo Calculation of pi in C++


pi<<algoritm

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
  cout<<"n = ";
  int n;
  cin>>n;
  srand(time(NULL));
  float x,y;
  int k=0;
  for(int i=1; i<=n; i++){
    x=rand()/double(RAND_MAX);
    y=rand()/double(RAND_MAX);
    if(x*x+y*y<=1) k++;
  };
  float p=4.*k/n;
  cout<<"pi = "<<setprecision(10)<<p<<endl;
  char c;
  cin>>c;
}

loadposition Spis-mod_AC_en}