Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- float Sum, i, n, Numerator;
- Sum = 0;
- printf("Subject: Calculate the amount \n");
- printf("Enter the 'n' number: \n");
- scanf_s("%f", & n);
- while (n < 1) {
- printf("Enter positive number \n");
- scanf_s("%f", & n);
- }
- for (int i = 1; i <= n; i++) {
- if (i % 2 == 0) {
- Numerator = 1;
- } else {
- Numerator = -1;
- }
- Sum = Sum + (Numerator / (2 * i));
- }
- printf("The amount is: %.3f \n", Sum);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement