Skip to content

Instantly share code, notes, and snippets.

@invatainfo
Created September 16, 2017 15:01
Show Gist options
  • Save invatainfo/603e4aa480c8298690f4c39e4418e366 to your computer and use it in GitHub Desktop.
Save invatainfo/603e4aa480c8298690f4c39e4418e366 to your computer and use it in GitHub Desktop.
#include <iostream.h>
void nule(int n, int a[100]) {
int i, aux;
for (i = 1; i < n; i++)
if (a[i] == 0 && a[i + 1] != 0) {
aux = a[i];
a[i] = a[i + 1];
a[i + 1] = aux;
if (i > 1)
i = i - 2;
}
}
void main() {
int i, n, a[100];
cin >> n;
for (i = 1; i <= n; i++)
cin >> a[i];
nule(n, a);
for (i = 1; i <= n; i++)
cout << a[i] << " ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment