Advertisement
rodrigofbm

Untitled

Dec 23rd, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int maxValor = 100;
  9.     int repetiu;
  10.     vector<int> tabela;
  11.     vector<int> ignorar_valores;
  12.    
  13.     //popular o vector
  14.     for(int x = 1; x <= maxValor; x++)
  15.         tabela.push_back(x);
  16.  
  17.     //verifica quais valores devem ser retirados de tabela posteriormente
  18.     for(unsigned int i = 1; i < tabela.size(); i++){
  19.         for(unsigned int j = (i+1); j < tabela.size(); j++){
  20.             if(tabela[j] % tabela[i] == 0)
  21.                 ignorar_valores.push_back(tabela[j]);
  22.         }
  23.     }
  24.  
  25.  
  26.     //verifica se o valor em tabela[h] deve ser ignorado
  27.     for(unsigned int h = 1; h < tabela.size(); h++){
  28.         unsigned int j = 0;
  29.         repetiu = 0;
  30.         for(; j < ignorar_valores.size(); j++){
  31.             if(tabela[h] == ignorar_valores[j]){
  32.                 repetiu++;
  33.             }
  34.         }
  35.         if(repetiu == 0){
  36.             cout << tabela[h] << ' ' ;
  37.         }
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement