Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. /*
  2. * test.c
  3. *
  4. * Created on: Feb 28, 2020
  5. * Author: cdamian
  6. *
  7. *
  8. *
  9. * calculul lui PI
  10. * 4x(1/1 - 1/3 + 1/5 - 1/7 ...)
  11. */
  12.  
  13.  
  14.  
  15. #include<stdio.h>
  16. int main(){
  17. int i, n;
  18. int semn = +1;
  19.  
  20. float pi = 0;
  21.  
  22. printf("dati n: ");
  23. scanf("%d", &n);
  24.  
  25. for(i = 1; i <=n ; i = i + 2){
  26.  
  27. pi = pi + semn / (float) i;
  28. semn = semn * (-1);
  29.  
  30. }
  31.  
  32. pi *= 4;
  33.  
  34. printf("pi = %f", pi);
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement