Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 28, 2022 19:40
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/4a496be7b8ab2058fd0f5e04d714fe48 to your computer and use it in GitHub Desktop.
Save parzibyte/4a496be7b8ab2058fd0f5e04d714fe48 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
bool esPrimo(int numero)
{
if (numero == 0 || numero == 1 || numero == 4)
{
return false;
}
for (int x = 2; x < numero / 2; x++)
{
if (numero % x == 0)
{
return false;
}
}
return true;
}
int main()
{
int cantidad = 10;
int arreglo[cantidad];
int i;
for (i = 0; i < cantidad; i++)
{
cout << "Ingresa el numero que va en la posicion " << i+1 << ": ";
cin >> arreglo[i];
}
for (i = 0; i < cantidad; i++)
{
int numero = arreglo[i];
if(esPrimo(numero)){
cout << numero << " es primo\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment