Posted By

indra on 10/29/10


Tagged

algorithm


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Show prime number


 / Published in: C#
 

How to use :

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

  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  

You need to login to post a comment.