Advertisement
Guest User

ЫЫЫЫЫ

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void cycle (int *a, int n)
  7. {
  8.     //Замена соседних с единицей
  9.     for (int i = 0; i < n; i++)
  10.     {
  11.         if (a[i] == 1)
  12.         {
  13.             a[i - 1] = 0;
  14.             a[i + 1] = 0;
  15.         }
  16.     }
  17.     //Вывод массива
  18.     for (int i = 0; i < n; i++)
  19.     {
  20.         cout << a[i];
  21.     }
  22.     cout << endl;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.     //Выделение памяти
  29.     int *a,n;
  30.     cout << " Enter Size - ";  cin >> n;
  31.     a = new int[n];
  32.  
  33.     //Ввод массива
  34.     int i;
  35.     for (i = 0; i < n; i++)
  36.     {
  37.         cout << "a[" << i << "] = "; cin >> a[i];
  38.     }
  39.  
  40.     //Вызов функции
  41.     cycle(a, n);
  42.  
  43.     //Освобождение памяти
  44.     delete[]a;
  45.  
  46.     system("pause");
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement