fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int n;
  5. double x = 1,y = 0,z;
  6.  
  7. scanf("%d",&n);
  8.  
  9. for (int i = 0 ;i < n;i++){
  10. z = x/(i*2+1);
  11. y = y + z;
  12. x = -x;
  13. }
  14. printf("%.6f",y);
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0.01s 5272KB
stdin
3
stdout
0.866667