# Primos de Una Lista
# Primos de Una Lista
WriteLine("
*** matriz ***");
Console.WriteLine("
------");
int m, n, x, i;
Console.WriteLine();
Console.Write(">> dimension: m = ");
m = int.Parse(Console.ReadLine());
Console.WriteLine();
Console.WriteLine(">> elementos:");
int [] a;
a = new int[m];
Console.WriteLine();
for (x = 0; x < m; x++)
{
Console.Write("
* ({0}) = ", x+1);
a[x] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
Console.WriteLine(">> lista 'a':");
Console.WriteLine();
for (x = 0; x < m; x++)
{
Console.WriteLine("\t{0}", a[x]);
}
Console.WriteLine();
Console.Write("buscar el elemento: ");
n = int.Parse(Console.ReadLine());
for (x = 0; x < m; x++)
{
if ((x+1) == n)
{
Console.WriteLine("el elemento {0} es: {1}", n, a[x]);
}
}
// numeros primos.
Console.WriteLine();
Console.WriteLine(">> numeros primos: ");
Console.WriteLine();
int c = 0;
for (x = 0; x < m; x++)
{
for (i = 1; i <= a[x]; i++)
{
if ((a[x]) % i == 0)
{
c++;
}
}
if (c <= 2)
{
Console.WriteLine("el elemento ({0}) = {1} es primo", x + 1, a[x]);
}
c = 0;
}
SOLO PRIMOS:
int m, n, x, i,c=0;
Console.WriteLine();
Console.Write(">> dimension: m = ");
m = int.Parse(Console.ReadLine());
Console.WriteLine(">> elementos:");
int[] a;
a = new int[m];
Console.WriteLine();
for (x = 0; x < m; x++)
{
Console.Write("
* ({0}) = ", x +1);
a[x] = int.Parse(Console.ReadLine());
}
for (x = 0; x < m; x++)
{
for (i = 1; i <= a[x]; i++)
{
if ((a[x]) % i == 0)
{
c++;
}
}
if (c <= 2)
{
Console.WriteLine("el elemento ({0}) = {1} es primo", x + 1, a[x]);
}
c = 0;
}
}
}
}
}