0
My code searches for prime numbers in a vector of 10 positions and displays only the prime numbers themselves, only the following error prevents their execution:
CS0165 Error: Unassigned local variable usage "prime"
using System;
namespace Vetor1
{
class Program2
{
static int Main(string[] args)
{
var vetor = new int[10];
int i, posicao, numeroprimo;
for (i = 0; i < vetor.GetLength(0); i++)
{
Console.Write($"Digite o {i}° número: ");
vetor[i] = int.Parse(Console.ReadLine());
do
{
if (vetor[i] <= 0)
{
Console.Write($"Digite o {i}° número: ");
vetor[i] = int.Parse(Console.ReadLine());
}
} while (vetor[i] <= 0);
}
for (i = 0; i < vetor.GetLength(0); i++)
{
if (vetor[i] > 1)
{
for (i = 2; i <= vetor.GetLength(0) - 1; i++)
{
if (vetor[i] % i == 0)
{
numeroprimo = 0;
break;
}
}
if (numeroprimo == 1)
{
posicao = i;
Console.WriteLine($"Posição {posicao}");
}
}
}
Console.ReadKey();
return 0;
}
}
}
I hadn’t noticed that you coded, went to see the code I posted and fixed some things and posted my own corrected code.
– Carlos A.
That previous question of mine to identify if an element of the vector is empty (no value typed) I still don’t understand what you mean.
– Carlos A.