C# Program to print odd numbers from 1 to N

In this C# program, we will take input from the user and print odd numbers between 1 and the number input by the user. An odd number is a positive integer that is not divisible by 2.

C# Program to print odd numbers from 1 to N Code:

private static void Main(string[] args)
        {
            Console.ForegroundColor= ConsoleColor.Yellow;

            int n, i, sum;
            Console.WriteLine("Enter the nth No");
            int nthNo = Int32.Parse(Console.ReadLine());
            Console.Write("Odd numbers between 1 and {0} are: ", nthNo);
            for (n = 1; n <= nthNo; n++)
            {
                if (n%2!=0)
                    Console.Write("{0} ", n);
            }
            Console.Write("\n");

            Console.ReadLine();
        }

C# Program to print odd numbers from 1 to N Output:

 
We are nothing without our users ! You can help us offer even more high quality content. Please share our page !
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
6 + 3 =
 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2022 CodingFusion
75 Important SQL Server queries you should know