Advertisement
ebx

drugi_kolokvijum_b_pi

ebx
May 3rd, 2012
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define TACNOST 0.001
  4.  
  5. int main (int argc, char** argv) {
  6.     int n=1;
  7.     double pi=2.0;
  8.     int potrebnaTacnost = 0;
  9.     while (potrebnaTacnost == 0) {
  10.         n+=2;
  11.         pi *= (double)(n-1)/n;
  12.         pi *= (double)(n+1)/n;
  13.         if ((1- (double)(n-1)/n) < TACNOST ) potrebnaTacnost=1;
  14.     }
  15.     pi *= 2;
  16.     printf("pi = %.3lf", pi);
  17.     getchar();
  18.     getchar();
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement