Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- int main()
- {
- SetConsoleOutputCP(1251);
- auto const n{ 15 };
- int x[n]{}, i{};
- double sum{}, arithmetic_mean{}, y[n]{};
- for (i = 0; i < n; i++) {
- while (true) {
- cout << "x[" << i << "] = ";
- cin >> x[i];
- if (cin.fail() || cin.peek() != '\n') {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- }
- cout << "Вихідний масив:" << endl;
- for (i = 0; i < n; i++) {
- cout << x[i];
- if (i < n - 1) {
- cout << ", ";
- }
- sum += x[i];
- }
- arithmetic_mean = sum / n;
- cout << fixed;
- cout.precision(2);
- cout << endl << "Середнє арифметичне - " << arithmetic_mean << endl;
- cout << "Новий масив:" << endl;
- for (i = 0; i < n; i++) {
- y[i] = x[i] - arithmetic_mean;
- cout << y[i];
- if (i < n - 1) {
- cout << ", ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement