Skip to content

Commit 38c58ac

Browse files
Gathrosleios
authored andcommitted
fixing percentage error in monte_carlo.c (#374)
1 parent 70ce21d commit 38c58ac

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

contents/monte_carlo_integration/code/c/monte_carlo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void monte_carlo(int samples) {
2424
double estimate = 4.0 * count / (samples * radius * radius);
2525

2626
printf("The estimate of pi is %f\n", estimate);
27-
printf("Which has an error of %0.2f%\n", 100 * (M_PI - estimate) / M_PI);
27+
printf("Percentage error: %0.2f%\n", 100 * fabs(M_PI - estimate) / M_PI);
2828
}
2929

3030
int main() {

0 commit comments

Comments
 (0)