Advertisement
Josif_tepe

Untitled

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