I attach the working code to match an approximation of pi.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;
int tabSize=720; //odd number recommended, max 32767
int precision=10000000;
long double round=0;
int number1, number2;
int main()
{
long double r=(long double)tabSize/2;
long double r2=r*r;
int s=tabSize/2+1;
int tab[tabSize][tabSize];
for(int i=0;i<tabSize;i++)
{
for(int j=0;j<tabSize;j++)
{
if((i-s)*(i-s)+(j-s)*(j-s)<=r2)
{
tab[i][j]=1;
}
else
{
tab[i][j]=2;
}
}
}
srand(time(NULL));
for(int i=0;i<precision;i++)
{
number1=rand()%tabSize;
number2=rand()%tabSize;
if(tab[number1][number2]==1)
{
round++;
}
}
round/=precision;
long double pi=round*tabSize*tabSize/r2;
cout << "Your pi approximation: " << setprecision(50) << pi << endl;
return 0;
}
Everything works, but if I increase tabSize to 721 or more, script crash: "Process returned -1073741571 (0xC00000FD)". What is more, this is a max value in CodeBlocks, because in QT Creator under Linux I can enter up to 1446 to tabSize variable. 1447 or more cause the same crash "Process returned -1073741571 (0xC00000FD)". What is the reason? Where is my fault?