×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

Print all Odd numbers from array of integers using C# program

Learn, how to print all ODD numbers from an array of integers?
[Last updated : March 19, 2023]

Printing ODD numbers from an array

Given array of integers, and we have to print all ODD numbers.

Example

Input:
18, 13, 23, 12, 27

Output:
18 is properly divisible by 2, So it is a not odd number.
13 is not properly divisible by 2, so it is a odd number.
23 is not properly divisible by 2, so it is a odd number.
12 is properly divisible by 2, So it is not a odd number.
27 is not properly divisible by 2, so it is a odd number.

C# program to print ODD numbers from an array

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
  class Program {
    static void Main() {
      int i = 0;
      //declaring array of integers
      int[] arr = new int[5];

      //reading the elements
      Console.WriteLine("Enter array elements : ");
      for (i = 0; i < arr.Length; i++) {
        Console.Write("Element[" + (i + 1) + "]: ");
        arr[i] = int.Parse(Console.ReadLine());
      }

      //checking and printing all odd numbers
      Console.WriteLine("List of odd  numbers : ");
      for (i = 0; i < arr.Length; i++) {
        //condition to check ODD number
        if (arr[i] % 2 != 0)
          Console.Write(arr[i] + " ");
      }
      Console.WriteLine();
    }
  }
}

Output

Enter array elements :
Element[1]: 10
Element[2]: 11
Element[3]: 12
Element[4]: 13
Element[5]: 14
List of odd  numbers :
11 13

C# Basic Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.