Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Calculate PAI by Leibniz infinite number serie
- * 3.141592653589793238462643383279502884197169399375105820974944592307816406286 ...
- * The program sums with each loop the result of 4*[(-1)^(n+1)]/(2*n-1)
- * to the value of pai
- *
- */
- float pai = 0; // the calculated value
- float oddNum = 1; // the value of the nominator
- int sign = 1;// the sign of the current sum
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- pai = pai + 4 * sign / oddNum;
- sign = -sign;
- oddNum = oddNum + 2;
- Serial.println(pai,10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement