Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. Module Module1
  2. Sub Main()
  3. Dim resposta As String
  4. Do
  5. Console.Write("Escreva um número inteiro entre 1 e 10000 ou 'Sair' para sair: ")
  6. resposta = Console.ReadLine().ToUpper
  7. If resposta <> "SAIR" Then
  8. Dim NUM As Integer
  9. If Integer.TryParse(resposta, NUM) Then
  10. If NUM >= 1 AndAlso NUM <= 10000 Then
  11. Dim Primo As Boolean = True 'Vamos assumir que é sempre um número primo até provarmos que não é
  12. If NUM > 3 Then
  13. For ciclo As Integer = 2 To (NUM - 1)
  14. If NUM Mod ciclo = 0 Then
  15. Primo = False
  16. Exit For
  17. End If
  18. Next ciclo
  19. End If
  20. If Primo Then
  21. Console.WriteLine(NUM.ToString + " é um número primo.")
  22. Else
  23. Console.WriteLine(NUM.ToString + " não é um múmero primo.")
  24. End If
  25. Else
  26. Console.WriteLine("O número que escreveu não é nenhum valor entre 1 e 10000")
  27. End If
  28. Else
  29. Console.WriteLine("Verifique se escreveu 'Sair' corretamente ou se pretendia introduzir um número")
  30. End If
  31. End If
  32. Loop While resposta <> "SAIR"
  33. End Sub
  34. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement