no recuerdo quién es el autor... pero no importa
#include <vector>
#include <iostream>
#include <conio.h>
void main(void)
{
const int sievesize = 300;
std::vector<int> sieve(sievesize, 1);
clrscr();
cprintf("\n << Criba de Erat¢stenes >>\n\n");
gotoxy(1, wherey());
for(int i=2; i*i<sievesize; i++)
if(sieve[i])
for(int j=i+i; j<sievesize; j+=i)
sieve[j] = 0;
for(int j=2; j<sievesize; j++){
if(sieve[j]){
textbackground(RED);
cprintf("%03d", j);
textbackground(BLUE);
cprintf(" ");
}
else { textbackground(BLUE);
cprintf("%03d ", j);
}
if(j == 19)
cprintf(" ");
if(j == 299)
cprintf(" ");
if(!(j % 19)){
cprintf("\n");
gotoxy(1, wherey());
}
}
textbackground(BLACK);
std::cout << std::endl;
}
Saludos desde Baires, JuanC