Q:

Write a C# program to check if an array contains an odd number

0

Write a C# program to check if an array contains an odd number

Sample Output:

Original array: [2, 4, 7, 8, 6]                                        
Check if an array contains an odd number? True

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

public class Exercise53
{  
   public static void Main() 
      {
         int[] nums = {2, 4, 7, 8, 6};
         Console.WriteLine("\nOriginal array: [{0}]", string.Join(", ", nums));
         Console.WriteLine("Check if an array contains an odd number? "+even_odd(nums));
      }  
        
    public static bool even_odd(int[] nums)  
    {
         foreach (var n in nums)
            {
                if (n % 2 != 0) 
                return true;
            }
        return false;
              
     } 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now