Friday, October 7, 2022

Pi

 // Calculation of the pi number using the area of the circle 
// and the area of the square circumscribed around a circle
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long int k; k = 0;
double x, y, piapr;
// Always set a seed value.
srand((unsigned int)time(NULL));
for (long long int i = 1; i < 10000000; i++)
{
x = (double)rand() / RAND_MAX;
y = (double)rand() / RAND_MAX;
if (x * x + y * y < 1) k++;
piapr = 4 * (double)k / i;
if ((i % 10000) == 9999) cout << piapr << " ";
}
return 0;
}

No comments:

Post a Comment

NaCl.xyz Generator with Interactive 3D Visualization

NaCl.xyz Generator with Interactive 3D Visualization NaCl.xyz Generator with Interactive 3D Visualization ...