antiblock
Rodnia | Alpha & Omega
  • Chatbox

    You don't have permission to chat.
    Load More
Sign in to follow this  
є๔ฬเภ5ς

Numeros Primos Até 100

9 posts in this topic

antiblock
Rodnia | Alpha & Omega

A string que estas a tentar converter para int, contêm texto, e obviamente, não pode conter letras, só numeros.

Share this post


Link to post
Share on other sites

Eu já percebi acho mas então como é que eu consigo que ele me apresente os primeiros 100 numeros para depois a formula verificar se é primo ou nao ?

Share this post


Link to post
Share on other sites

Queres verificar se 100 numeros são primos, é isso?

Reformula a questão

Share this post


Link to post
Share on other sites

static void main(...)

{

Console.WriteLine("Xuta ai um numero");

int n1 = Convert.ToInt32(Console.ReadLine());

for(i = 1; i < 101; i++)

{

if(IsPrimo(n1, i))

Console.WriteLine("O " + i + " é primo.")

else

Console.WriteLine("O " + i + " não é primo.")

}

Console.ReadKey()

}

static bool IsPrimo(int n1, int n2)

{

if(n1 % n2 == 0)

return false;

return true;

}

Share this post


Link to post
Share on other sites

Mas não é isso que eu quero o que eu quero basicamente é que dos primeiros 100 números ele me diga quais são primos e quais não são  sem eu ter que dar 1 valor tas a perceber? XD não sei se é preciso usar vetores ou não.. XD 

 

 

 Um subprograma para calcular os 100 primeiros números primos

Share this post


Link to post
Share on other sites

static void main(...)

{

for(i = 1; i < 101; i++)

{

if(IsPrimo(i))

Console.WriteLine("O " + i + " é primo.")

else

Console.WriteLine("O " + i + " não é primo.")

}

Console.ReadKey()

}

static bool IsPrimo(int n1)

{

if(n1 % 1 == 0)

return false;

return true;

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this