Advertisement
Atheuz

Untitled

Oct 24th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.    
  5.     double out = 1;
  6.     int parity = 0;
  7.     int i;
  8.  
  9.     for(i=3; i <= 99; i+=2) {
  10.         if(parity == 0) {
  11.             out -= (1.0/i);
  12.             parity = 1;
  13.         }
  14.         else if(parity == 1) {
  15.             out += (1.0/i);
  16.             parity = 0;
  17.         }
  18.     }
  19.  
  20.     out *= 4.0;
  21.  
  22.     printf("pi is approximately equal to %f", out);
  23.  
  24.     return 0;
  25. }
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement