C# Code: Write a C# Console Application program to print odd numbers between 1 to 100 using for loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Program { static void Main(string[] args) { for (int i = 1; i <= 100; i++) { if (i % 2 == 1) { Console.Write(i+" "); } } Console.ReadLine(); } } |
C# Code: Write a C# Console Application program to print odd numbers between 1 to 100 using while loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | class Program { static void Main(string[] args) { int i = 0; while (true) { i++; if (i % 2 == 1) { Console.Write(i + " "); } if (i >= 100) break; } Console.ReadLine(); } } |
Output:
C# Program to Print Odd Numbers Between 1 to 100