Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     float Sum, i, n, Numerator;
  5.     Sum = 0;
  6.     printf("Subject: Calculate the amount \n");
  7.     printf("Enter the 'n' number: \n");
  8.     scanf_s("%f", & n);
  9.     while (n < 1) {
  10.         printf("Enter positive number \n");
  11.         scanf_s("%f", & n);
  12.     }
  13.     for (int i = 1; i <= n; i++) {
  14.         if (i % 2 == 0) {
  15.             Numerator = 1;
  16.         } else {
  17.             Numerator = -1;
  18.         }
  19.         Sum = Sum + (Numerator / (2 * i));
  20.     }
  21.     printf("The amount is: %.3f \n", Sum);
  22.     getch();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement