Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. /*одн линам массив. вывести четные, отриц заменит на 0. потом нулевые заменить на полоусумму соседних*/
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n, i;
  10.     cout << "Input array size: "; cin >> n;
  11.     int *mas = new int[n];
  12.     for (i = 0; i < n; i++)
  13.     {
  14.         cout << "Input massive element " << i << ": "; cin >> mas[i];
  15.     }
  16.     cout << "The array is: " << endl;
  17.     for (i = 0; i < n; i++) cout << mas[i] << "\t";
  18.     cout << endl;
  19.     //четные
  20.     cout << "the array of tchetnye elements is:" << endl;
  21.     for (i = 0; i < n; i++)
  22.     {
  23.         if (mas[i] % 2 == 0)
  24.             cout << mas[i] << "\t";
  25.     }
  26.     cout << endl << "Otritsatelnye are zero:" << endl;
  27.     for (i = 0; i < n; i++)
  28.     {
  29.         if (mas[i] % 2 == 0) {
  30.             if (mas[i] < 0)
  31.                 mas[i] = 0;
  32.             cout << mas[i] << "\t";
  33.         }
  34.     }
  35.     cout << endl;
  36.     for (i = 1; i < n-1; i++)
  37.         if (mas[i] == 0) mas[i] = (mas[i - 1] + mas[i + 1]) / 2;
  38.     for (i = 0; i < n; i++)
  39.     {
  40.             cout << mas[i] << "\t";
  41.     }
  42.    
  43.    
  44.     delete[]mas;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement