Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Print the odd numbers from 1 to 99

C# Sharp Basic: Exercise-25 with Solution

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

C# Sharp Exercises: Print the odd numbers from 1 to 99

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise25
{  
    public static void Main() 
      {     
          Console.WriteLine("Odd numbers from 1 to 99. Prints one number per line.");
          for (int n = 1; n < (99 + 1); n++)
            {
                if (n % 2 != 0)
                {
                    Console.WriteLine(n.ToString());
                }
            }
                    
    }
}

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 
73                                                                     
75                                                                     
77                                                                     
79                                                                     
81                                                                     
83                                                                     
85                                                                     
87                                                                     
89                                                                     
91                                                                     
93                                                                     
95                                                                     
97                                                                     
99 

Flowchart:

Flowchart: C# Sharp Exercises - Print the odd numbers from 1 to 99

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to find the longest word in a string.
Next: Write a C# program to compute the sum of the first 500 prime numbers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.