add a few asserts to make approximating pi more reliable
This commit is contained in:
parent
2531b2b3c5
commit
f1adfa76d9
1 changed files with 7 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -19,7 +20,12 @@ double approximate_pi(unsigned int steps) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// printf("sizeof(int) = %d\n", sizeof(int));
|
// printf("sizeof(int) = %d\n", sizeof(int));
|
||||||
printf("pi = %8.7f\n", approximate_pi(10000000));
|
|
||||||
|
double mypi = approximate_pi(100000000);
|
||||||
|
|
||||||
|
printf("pi = %8.7f\n", mypi);
|
||||||
|
assert(mypi > 3.141);
|
||||||
|
assert(mypi < 3.142);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue