From 0912b5f6998b3642f0a90ddafed3e9d5a2c74962 Mon Sep 17 00:00:00 2001 From: Gathros <6323830+Gathros@users.noreply.github.com> Date: Tue, 11 Sep 2018 15:32:50 +0100 Subject: [PATCH] fixing percentage error in monte_carlo.c --- contents/monte_carlo_integration/code/c/monte_carlo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/monte_carlo_integration/code/c/monte_carlo.c b/contents/monte_carlo_integration/code/c/monte_carlo.c index 65b435fb8..b63896dd3 100644 --- a/contents/monte_carlo_integration/code/c/monte_carlo.c +++ b/contents/monte_carlo_integration/code/c/monte_carlo.c @@ -24,7 +24,7 @@ void monte_carlo(int samples) { double estimate = 4.0 * count / (samples * radius * radius); printf("The estimate of pi is %f\n", estimate); - printf("Which has an error of %0.2f%\n", 100 * (M_PI - estimate) / M_PI); + printf("Percentage error: %0.2f%\n", 100 * fabs(M_PI - estimate) / M_PI); } int main() {