negtab

1.19.2 C++

Sep 11th, 2024 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n;
  6.     double sum;
  7.     bool isNotCorrect;
  8.  
  9.     sum = 0.0;
  10.  
  11.     cout << "Эта программа вычисляет сумму по формуле S от 1 до n 1/i^3" << endl;
  12.  
  13.     do {
  14.         cout << "Введите число n от 1 до 200" << endl;
  15.         isNotCorrect = false;
  16.         cin >> n;
  17.         if (cin.fail())
  18.         {
  19.             isNotCorrect = true;
  20.             cin.clear();
  21.             while (cin.get() != '\n');
  22.             cout << "Пожалуйста, вводите числа" << endl;
  23.         }
  24.     }
  25.     while(isNotCorrect);
  26.  
  27.     for(int i = 1; i <= n; i++)
  28.     {
  29.         sum += 1.00/(i*i*i);
  30.     }
  31.  
  32.     cout << "Сумма равна: " << sum << endl;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment