Show prime number


/ Published in: C#
Save to your folder(s)

How to use :

Compile and then run in your command line with some number parameter you want to check = PrimeNumber 1 3 5 10


Copy this code and paste it in your HTML
  1. public class PrimeNumber
  2. {
  3.  
  4. public static void Main(string[] args)
  5. {
  6. for (int i = 0; i < args.Length; i++)
  7. {
  8. if (IsPrimeNumber(int.Parse(args[i])))
  9. {
  10. System.Console.WriteLine(args[i]);
  11. }
  12. }
  13. }
  14.  
  15. public static bool IsPrimeNumber(int pNumber)
  16. {
  17. bool prime = true;
  18.  
  19. for (int i = 2; i < pNumber; i++)
  20. {
  21. if (pNumber % i == 0)
  22. {
  23. prime = false;
  24. }
  25. }
  26. return prime;
  27. }
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.