C# Program to Print Odd Numbers in a Given Range

This is a C# Program to generate odd numbers within a range.

Problem Description

This C# Program Generates Odd Numbers within a Range.

Problem Solution

Here Enumerable.Range generates a collection of odd numbers of a specified range. It can simplify numeric lists and drop-downs in Windows Forms program.

Program/Source Code

Here is source code of the C# Program to Generate Odd Numbers within a Range. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program to Caluculate the power exponent value
 */
using System;
using System.Collections.Generic;
using System.Linq;
class program
{
    static void Main(string[] args)
    {
        IEnumerable<int> oddNums =
 
            Enumerable.Range(20, 20).Where(x => x % 2 != 0);
 
        foreach (int n in oddNums)
        {
            Console.WriteLine(n);
        }
        Console.ReadLine();
 
    }
}
Program Explanation

This C# program generates odd numbers within a range. The Enumerable.Range generates a collection of odd numbers of a specified range. It can simplify numeric lists and drop-downs in Windows Forms program. Using foreach loop print the odd numbers in the range.

advertisement
advertisement
Runtime Test Cases
 
21
23
25
27
29
31
33
35
37
39

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.