avr39-ripe

dmit_Zeros

Mar 5th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <chrono>
  4. using namespace std;
  5. //Создать массив из 10 элементов..
  6. int main() {
  7.     const int size = 10;     //константа, хранящая размер массива
  8.     int array[size] = { 0, 1, 0, 0, 4, 0, 6, 7, 0, 9 }; //объявление и инициализация одномерного массива
  9.     int count0 = 0;
  10.     for (int idx = 0; idx < size - count0; idx++) {
  11.         if (array[idx] == 0) {
  12.             count0++;
  13.             for (int j = idx; j < size - count0; j++) { array[j] = array[j + 1]; }
  14.             array[size - count0] = 0;
  15.             idx--;
  16.         }
  17.  
  18.     }
  19.     for (int idx = 0; idx < size; idx++) {
  20.         cout << "array[" << idx << "] = " << array[idx] << endl;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment