How To Find Prime Numbers From 1 To 100 Using C#

  1. using System;  
  2. class Program {  
  3.     static void Main() {  
  4.         //Declaration  
  5.         bool isPrime = true;  
  6.         int i, j;  
  7.         //Calculate and display the Prime number  
  8.         Console.WriteLine("Prime Numbers are : ");  
  9.         for (i = 2; i <= 100; i++) {  
  10.             for (j = 2; j <= 100; j++) {  
  11.                 if (i != j && i % j == 0) {  
  12.                     isPrime = false;  
  13.                     break;  
  14.                 }  
  15.             }  
  16.             if (isPrime) {  
  17.                 Console.Write("\t" + i);  
  18.             }  
  19.             isPrime = true;  
  20.         }  
  21.         Console.ReadKey();  
  22.     }  
  23. }