Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- int main()
- {
- bool primo;
- // Inicializa o número a ser testado e um contador 'i'
- // que indica a quantidade de primos exibidos.
- for(int num = 2, i = 1; i <= 500; num++)
- {
- for(int j = 2; j < num; j++)
- {
- // Verifica se 'num' é divisível por algum número
- // entre 2 e 'num' - 1.
- if(num%j == 0)
- {
- primo = false;
- break;
- }
- else
- primo = true;
- }
- if((primo)||(num == 2))
- {
- cout << "\n" << i << ": " << num;
- i++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement