avr39-ripe

vukst_Zeros

Mar 5th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     const int size = 10;
  10.     int arr[size] = { 1,0,2,0,3,0,4,0,5,0 };
  11.     int temp = 0;
  12.  
  13.     for (int i = size-1; i > 0; ) {
  14.        
  15.         if (arr[i] == 0 && arr[i-1] != 0)
  16.         {
  17.             temp = arr[i-1];
  18.             arr[i-1] = arr[i];
  19.             arr[i] = temp;
  20.             i = size-1;
  21.             continue;
  22.         }
  23.  
  24.         else {
  25.             i--;
  26.             continue;
  27.         }
  28.     }
  29.  
  30.     for (int i = 0; i < size; i++) {
  31.         cout << " " << arr[i] << " ";
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment