Here prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Here is source code of the C# Program to Display All the Prime Numbers Between 1 to 100.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
static void Main(string[] args) { int count=0; Console.WriteLine("Prime numbers between 1 and 100 are: "); Console.WriteLine("=============================================="); for (int i = 1; i < 101; i++) { count = 0; if (i > 1) { for (int j = 2; j < i; j++) { if (i % j == 0) { count = 1; break; } } if (count == 0) { Console.Write(i+" "); } } |
Output: