C#: Print the odd numbers from 1 to 99
Print Odd Numbers 1 to 99
Write a C# program to print odd numbers from 1 to 99. Prints one number per line.

Sample Solution:-
C# Sharp Code:
using System;
// This is the beginning of the Exercise25 class
public class Exercise25
{
// This is the main method where the program execution starts
public static void Main()
{
Console.WriteLine("Odd numbers from 1 to 99. Prints one number per line."); // Displaying a message
// Loop to print odd numbers from 1 to 99, one number per line
for (int n = 1; n < (99 + 1); n++)
{
if (n % 2 != 0) // Checking if the number is odd by using the modulo operator
{
Console.WriteLine(n); // Printing the odd number
}
}
}
}
Sample Output:
Odd numbers from 1 to 99. Prints one number per line. 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C# program to print all odd numbers from 1 to 99, but skip those divisible by 5.
- Write a C# program that prints the sum of all odd numbers from 1 to 99.
- Write a C# program that prints odd numbers in reverse from 99 to 1.
- Write a C# program to print all odd numbers and indicate whether each is a prime.
Go to:
PREV : Find Longest Word in String.
NEXT :Sum of First 500 Primes.
C# Sharp Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.