Advertisement
Atheuz

Untitled

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