Advertisement
Sanlover

Untitled

Nov 2nd, 2021
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.   double X, E, E10, summary = 0, summaryE = 0, summaryE10 = 0;
  8.   int N, amountE = 0, amountE10 = 0;
  9.  
  10.   cout << "Enter X: ";
  11.   cin >> X;
  12.  
  13.   if (X <= -1 || X >= 1) {
  14.     cout << "X must be in (-1;1).";
  15.     return 0;
  16.   }
  17.  
  18.   cout << "Enter E: ";
  19.   cin >> E;
  20.   if (E < 0) {
  21.     cout << "Your E is negative but must be nonnegative. E will be absoulte.";
  22.     E = abs(E);
  23.   }
  24.   E10 = E / 10;
  25.  
  26.   cout << "Enter N: ";
  27.   cin >> N;
  28.   if (N < 0) {
  29.     cout << "N must be nonnegative";
  30.     return 0;
  31.   }
  32.  
  33.   double term = 1;
  34.   for (int i = 0; i < N; i++) {
  35.     summary += term;
  36.     if (abs(term) > E10) {
  37.       if (abs(term) > E) {
  38.         summaryE += term;
  39.         amountE++;
  40.       }
  41.       summaryE10 += term;
  42.       amountE10++;
  43.     }
  44.     term *= -X;
  45.   }
  46.  
  47.   cout << endl << "Results:" << endl;
  48.   cout << "1/(1+x) = " << 1.0 / (1.0 + X) << endl;
  49.   cout << "Summary of N(" << N << ") elements is equal to " << summary << endl;
  50.   cout << "Summary of (" << amountE
  51.        << ") elements, which absolute value is higher than E(" << E
  52.        << ") equals to " << summaryE << endl;
  53.   cout << "Summary of (" << amountE10
  54.        << ") elements, which absolute value is higher than E10(" << E10
  55.        << ") equals to " << summaryE10 << endl;
  56.   return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement