Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 5, 2020 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ebbe9d1878be81fa927caafedc82f031 to your computer and use it in GitHub Desktop.
Save parzibyte/ebbe9d1878be81fa927caafedc82f031 to your computer and use it in GitHub Desktop.
/*
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
Copyright (c) 2020 Luis Cabrera Benito
Licenciado bajo la licencia MIT
El texto de arriba debe ser incluido en cualquier redistribución
*/
#include <iostream>
bool esPrimo(int numero) {
// Casos especiales
if (numero == 0 || numero == 1 || numero == 4)
return false;
for (int x = 2; x < numero / 2; x++) {
if (numero % x == 0)
return false;
}
// Si no se pudo dividir por ninguno de los de arriba, sí es primo
return true;
}
int main() {
int matriz[5][5];
int contador = 1;
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 5; y++) {
while (true) {
contador++;
if (esPrimo(contador)) {
matriz[x][y] = contador;
break;
}
}
}
}
// imprimir
for (int x = 0; x < 5; x++) {
std::cout << "\n";
for (int y = 0; y < 5; y++) {
std::cout << matriz[x][y] << " ";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment