/dev/urandom

@cat

Joined 27 Jul 2021

hi i exist lol

1 following 4 followers


Articles



First Article
Published 27 Jul 2021

#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>

/**
 * Estimate PI using Leibiniz series
 * 1 - (1/3) + (1/5) - (1/7) + (1/9) .... = (pi / 4)
 */

void calc(int terms) {
    long double pi = M_PI;

    long double sum = 0;
    long long int denom = 1;

    for(int i = 0; i < terms; i++) {
        sum += pow(-1, i) * ( 1 / double(denom) );
        denom += 2;
        long double estimate = sum * 4;
        long double diff = abs(pi - estimate);
        std::cout ...
106 views