Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int n;
- bool isInCorrect;
- cout << "Данная программа предназначена для формирования сглаженного массива." << endl;
- do
- {
- isInCorrect = false;
- cout << "Введите количество элементов массива: ";
- cin >> n;
- if (cin.get() != '\n')
- {
- cin.clear();
- while (cin.get() != '\n');
- isInCorrect = true;
- cout << "Введите верные данные!" << endl;
- }
- if (!isInCorrect && n < 1)
- {
- isInCorrect = true;
- cout << "Введите верные данные!" << endl;
- }
- }
- while (isInCorrect);
- double *arr = new double[n];
- for (int i = 0; i < n; i++)
- {
- do
- {
- isInCorrect = false;
- cout << "Введите " << i + 1 << " элемент:";
- cin >> arr[i];
- if (cin.get() != '\n')
- {
- cin.clear();
- while (cin.get() != '\n');
- isInCorrect = true;
- cout << "Введите верные данные!" << endl;
- }
- }
- while (isInCorrect);
- }
- double *newarr = new double[n];
- newarr[0] = arr[0];
- newarr[n - 1] = arr[n - 1];
- for (int i = 1; i < n - 1; ++i)
- {
- newarr[i] = (arr[i - 1] + arr[i] + arr[i + 1]) / 3.0;
- }
- cout << "Сглаженный массив:" << endl;
- for (int i = 0; i < n; ++i)
- {
- cout << fixed << setprecision(2) << newarr[i] << endl;
- }
- delete[] arr;
- delete[] newarr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement