Advertisement
Josif_tepe

Untitled

Nov 22nd, 2023
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int n;
  5.     scanf("%d", &n);
  6.  
  7.     float result = 1;
  8.  
  9.     for(int i = 2; i <= n; i++) {
  10.         if(i % 2 == 0) {
  11.             result -= 1.0 / (float) (i);
  12.         }
  13.         else {
  14.             result += 1.0 / (float) (i);
  15.         }
  16.     }
  17.     printf("%f\n", result);
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement