Advertisement
jacknpoe

"juntando na chincha"

Nov 26th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #define TAMANHO 10
  4.  
  5. int main( void) {
  6.    int vetor[ TAMANHO] = { 1, 0, 3, 0, 56, 1, 0, 23, 0, 0 };
  7.     int destino = 0, origem = 0;
  8.  
  9.     while( origem < TAMANHO) {
  10.         if( vetor[ origem] == 0) {
  11.             origem++;
  12.             continue;
  13.         }
  14.         vetor[ destino] = vetor[ origem];
  15.         origem++;
  16.         destino++;
  17.     }
  18.     for( int i = destino; i < TAMANHO; i++) vetor[ i] = 0;
  19.     for( int i = 0; i < TAMANHO; i++) std::cout << vetor[ i] << "\n";
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement