Advertisement
cortez

Prime Numbers

Oct 7th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using System;
  2.  
  3. namespace prime
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main (string[] args)
  8.         {
  9.             int a;
  10.             int n;
  11.             int.TryParse(Console.ReadLine(), out n);
  12.             Console.WriteLine ("The prime numbers in the range from 0 to " + n + " are: ");
  13.             for (a = 2; a <= n; a++)
  14.             {
  15.                 bool res1 = ((a % 2) == 0);
  16.                 bool res2 = ((a % 3) == 0);
  17.                 bool res3 = ((a % 5) == 0);
  18.                 bool res4 = ((a % 7) == 0);
  19.                 if (!res1 && !res2 && !res3 && !res4)
  20.                 {
  21.                     Console.WriteLine (a);
  22.                 }
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement