Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- using namespace std;
- int main() {
- double X, E, E10, summary = 0, summaryE = 0, summaryE10 = 0;
- int N, amountE = 0, amountE10 = 0;
- cout << "Enter X: ";
- cin >> X;
- if (X <= -1 || X >= 1) {
- cout << "X must be in (-1;1).";
- return 0;
- }
- cout << "Enter E: ";
- cin >> E;
- if (E < 0) {
- cout << "Your E is negative but must be nonnegative. E will be absoulte.";
- E = abs(E);
- }
- E10 = E / 10;
- cout << "Enter N: ";
- cin >> N;
- if (N < 0) {
- cout << "N must be nonnegative";
- return 0;
- }
- double term = 1;
- for (int i = 0; i < N; i++) {
- summary += term;
- if (abs(term) > E10) {
- if (abs(term) > E) {
- summaryE += term;
- amountE++;
- }
- summaryE10 += term;
- amountE10++;
- }
- term *= -X;
- }
- cout << endl << "Results:" << endl;
- cout << "1/(1+x) = " << 1.0 / (1.0 + X) << endl;
- cout << "Summary of N(" << N << ") elements is equal to " << summary << endl;
- cout << "Summary of (" << amountE
- << ") elements, which absolute value is higher than E(" << E
- << ") equals to " << summaryE << endl;
- cout << "Summary of (" << amountE10
- << ") elements, which absolute value is higher than E10(" << E10
- << ") equals to " << summaryE10 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement